15:00, EEST
June 14, 2022
Hello,
Using the Java SDK I want to create subscription, which receives all updates for all variable changes from a PLC added to a server. However I don’t know the structure of the PLC beforehand and want to get it programmatically and I expected that there will be a lot of nested nodes (folders) until it gets to a variable node.
I was thinking of traversing the whole structure recursively using uaClient.getAddressSpace().browse() until I reach all leaves of the tree and create MonitoredDataItem from those nodes, but my concern is that this could take a long time for PLCs with loads of nodes.
Is there an existing method to traverse all nodes or should I implement DFS myself? Also is there another smarter way to get all the variable nodes in the PLC?
15:53, EEST
Moderators
February 11, 2020
Hello,
First of all, monitoring all Variables on a Server’s AddressSpace for changes sounds like a very bad idea. Depending on the Server, there can hundreds or even thousands of Variables. Monitoring them all would put quite a heavy load the Server and possibly on the Client as well.
And if you do not know the structure of the PLC beforehand, what would be the significance of the received data changes? There is no guarantee that the NodeIds, BrowseNames or DisplayNames on the Server would give enough semantic meaning to the Variables you monitor, so understanding the structure of the PLC might be required to interpret the received data changes. And if you know the structure of the PLC, you don’t have to traverse the entire AddressSpace for Variables and you can just monitor those that represent important information.
That being said, recursive browsing with browse methods of AddressSpace class, such as browse(NodeId nodeId), is the only way of traversing the entire AddressSpace. Since OPC UA doesn’t have a strict parent-child hierarchy for Nodes, it is possible to reach a Node with multiple BrowsePaths so you have to keep track of Nodes that have already been processed to avoid processing them more than once.
17:36, EEST
June 14, 2022
So basically I am trying to rework an already existing application. We are already subscribing to hundreds of Variables and we must continue to support this, so every Variable change is important to us. Because of the hierarchy of folders in the PLC we have determined that the NodeId of the Variable together with Description and possibly DataType is going to provide enough information about the Variable and will give us the structure of the PLC.
Currently stl files with the structure of the PLC are being uploaded to our system and we get the NodeIds of the Variables through those files. However this method is prone to errors since when the structure of the PLC changes a new file needs to be uploaded to our system in order to start tracking the changes. That’s why I want to get this information directly from the server. Is there actually a way to track when the structure of the PLC was changed and how – for example new Variables were added, some nodes were deleted or a Variable description was changed? If a Variable is added as a MonitoredDataItem to a Subscription what will happen if that Variable is deleted from the PLC or it’s DataType is changed?
8:45, EEST
Moderators
February 11, 2020
Hello,
If the Server generates them, you could monitor the Server’s Server Object for ModelChangeEvents. Those Events are generated when Nodes or References are added or deleted and also when DataType Attributes of Variables change. Handling ModelChangeEvents would make it easier for your Client to react to changes in the Server’s AddressSpace. However, Servers are not required to generate ModelChangeEvents so you might not be able to rely on them.
For more information on ModelChangeEvents and how they express the changes using ModelChangeStructureDataType, see https://reference.opcfoundation.org/v105/Core/docs/Part3/#9.32 https://reference.opcfoundation.org/Core/docs/Part5/6.4.32/ and https://reference.opcfoundation.org/Core/docs/Part5/12.16/
If the Server doesn’t generate ModelChangeEvents, there isn’t any way to detect changes in the AddressSpace except by periodically browsing it from root to leaves to check for changes.
You can create MonitoredItems for other Attributes in addition to the typical Value Attribute. If you think that the Descriptions of Variables could change, you can create MonitoredItems to monitor changes in the Description Attributes of Variable Nodes. You could also monitor DataType Attributes if the Server doesn’t generate ModelChangeEvents and you think those could change too.
If a Variable Node on the Server corresponding to a MonitoredItem is deleted, the Server is expected to send a Notification for that MonitoredItem with StatusCode Bad_NodeIdUnknown to indicate that the Variable has been deleted. For more information, see https://reference.opcfoundation.org/Core/docs/Part4/5.12.1/#5.12.1.6
A change in the DataType Attribute of a Variable Node won’t affect a MonitoredItem monitoring the Value Attribute of the same Variable. You would keep receiving Notifications for new Values of the Variable, though their DataType would be different than before. As mentioned before, if you expect this to happen, you can monitor the DataType Attributes of Variable Nodes as well.
Most Users Ever Online: 1919
Currently Online:
21 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 88
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 735
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1523
Posts: 6449
Newest Members:
rust, christamcdowall, redaahern07571, nigelbdhmp, travistimmons, AnnelCib, dalenegettinger, howardkennerley, Thomassnism, biancacraft16Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1026, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0
Administrators: admin: 1