Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitoring / Subscription of multiple objects #1

Open
Ralalu opened this issue Dec 10, 2022 · 1 comment · May be fixed by #4
Open

Monitoring / Subscription of multiple objects #1

Ralalu opened this issue Dec 10, 2022 · 1 comment · May be fixed by #4

Comments

@Ralalu
Copy link

Ralalu commented Dec 10, 2022

Hi Luis

You could put multiple addresses in one subscription.
I did it like this:

Note: I need the namespace 3. In your code, the value is fixed to value 2.

        public ushort namespaceIndex = 3;

        List<MonitoredItem> itemsMulti;
        public void MonitoringMultiInit()
        {
           itemsMulti = new List<MonitoredItem>();        
        }
        
        public void MonitoringMulti(string address, MonitoredItemNotificationEventHandler monitor)
        {
            MonitoredItem monitored = new MonitoredItem();
            monitored.StartNodeId = new NodeId(address, namespaceIndex);
            monitored.AttributeId = Attributes.Value;
            monitored.Notification += monitor;
            itemsMulti.Add(monitored);
        }

        public void MonitoringMultiExec(int miliseconds)
        {
            var subscription = this.Subscription(miliseconds);
            subscription.AddItems(itemsMulti);
            this.Session.AddSubscription(subscription);
            subscription.Create();
            subscription.ApplyChanges();
        }

How to use

client.MonitoringMultiInit();
 client.MonitoringMulti("Device.Counter.Value1", (_, e) => {
   // Anything you need to be executed when the value changes
 
   // Get the value of the tag being monitored
    var monitored = (MonitoredItemNotification)e.NotificationValue;
    Console.WriteLine(monitored.Value);
 });
 client.MonitoringMulti("Device.Counter.Value2", (_, e) => {
   // Anything you need to be executed when the value changes
 
   // Get the value of the tag being monitored
    var monitored = (MonitoredItemNotification)e.NotificationValue;
    Console.WriteLine(monitored.Value);
 });
//....... add up to 1000 for Siemens S7 PLC
client.MonitoringMultiExec(1000);

regards
RaLa

@joc-luis
Copy link
Owner

Hi @Ralalu, if you want make a pull request for your changes, do not forget add an example in the README.md

@ekmart ekmart linked a pull request May 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants