OPCFoundation / UA-.NET-Legacy

OPC Foundation Unified Architecture .NET Reference Implementations
330 stars 297 forks source link

Stupid question about receiving multiple data changes at same time #98

Open startemplar opened 7 years ago

startemplar commented 7 years ago

I am still reading documentation but would like to quickly check:

  1. In OPC UA, can client retrieve multiple variable values at the same time (e.g. add multiple monitoredItems in one subscription)?
  2. If I use the single monitoredItem approach, is it safe to assume that older variable value will always be published to broker earlier than later variable values? Thank you.
jayantad commented 7 years ago
  1. Yes, you can definitely have multiple monitored items in a single subscription.

  2. It is upto the UA server to make sure that the published value is always the latest, but my understanding is that UA spec guarantees that Client receives the notifications in the same order as sent from the UA Server.

astrowalker commented 7 years ago

ad.2) the client should check timestamps and based on that decide what is newer. (@jayantad this is more about protocol used, not OPC, besides OPC when asked can send a batch of data, so order of sending/receiving would not help client to sort them out). And just for record please note there are two kinds of timestamps, server ones and source ones.

startemplar commented 7 years ago

Thanks, @jayantad and @astrowalker , I found Session.ReadValues method can accept a list of variableIds. Also from OPC UA spec, it supports pub/sub (which is monitoredItem approach), and request/response style of retrieving values (maybe Session.ReadValues method is this style). Currently no sample code using this method, trying to experiment if it meets the need.

startemplar commented 7 years ago

I found Subscription class has 1 event handler FastDataChangeNotificationEventHandler that seems to match my goal. Suppose the following scenario, a device may expose several parameters. In OPC UA, it would be represented as a device node with some child nodes (maybe even nodes under child nodes). I think my option is create 1 subscription for the device, add all the childe nodes I want to monitor as monitored items to this subscription, and in 1 callback, I can get all changed node values. It is a hidden gem in OPC UA .NET :-). Of course, I now have another question about how to extend OPC UA client configuration file to say for this device I have these sets of nodes to monitor, that device another sets of nodes to monitor. Think I have to look into source code (have not find documentation yet).