Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
How to get node parent in uaServer
August 26, 2021
16:12, EEST
Avatar
Sabari
Member
Members
Forum Posts: 62
Member Since:
June 21, 2021
sp_UserOfflineSmall Offline

Hi,
Does the sdk provide a method to get a node’s parent in uaServer ?

Thanks

August 27, 2021
9:20, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 321
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello,

First of all, OPC UA doesn’t have a strict parent-child hierarchy for Nodes. While you could say that a Node that targets another Node with a forward (non-inverse) Reference is the parent of the targeted Node, there could be other Nodes that also target the same Node making it possible for a Node to have multiple parents. And since there are multiple ReferenceTypes, the hierarchy of Nodes could look completely different for two different ReferenceTypes depending on the semantics of the used ReferenceTypes.

OPC UA Information Models use ParentNodeIds to express parent-child relationships between Nodes. However, the specification states (in https://reference.opcfoundation.org/Core/docs/Part6/F.7/) that “this information does not appear in the AddressSpace and is intended for use by design tools”, which is why there is no method that could be used to get this NodeId.

You could use UaNode.getReferences(NodeId referenceTypeId, boolean isInverse) where you specify a ReferenceType, e.g. HasComponent, with its NodeId, or use null for all ReferenceTypes, and set isInverse to true to get inverse References. Note, that the Prosys OPC UA SDK for Java handles all References internally as non-inverse References, which means that the UaNode that called the method is the target Node of the returned UaReferences! You could consider the source Nodes of the returned UaReferences as the parents of the UaNode.

October 12, 2021
14:44, EEST
Avatar
Sabari
Member
Members
Forum Posts: 62
Member Since:
June 21, 2021
sp_UserOfflineSmall Offline

Hello,

Thank you for your relply

October 19, 2023
18:44, EEST
Avatar
Jeremy Morgan
Member
Members
Forum Posts: 15
Member Since:
November 6, 2019
sp_UserOfflineSmall Offline

I am trying to do a similar thing (find the parent nodes of a given node). I have tried this:

UaNode node = uaClient.getAddressSpace().getNode(nodeId);
UaReference[] parentReferences = node.getReferences(Identifiers.HasComponent, true);

However, the UaReference array is always empty, and I know the node has a parent.

I also tried this (as mentioned in https://forum.prosysopc.com/forum/opc-ua-java-sdk/get-browse-path-by-nodeid/):

UaReference[] parentReferences = node.getReferences(Identifiers.HierarchicalReferences, true);

But the same, the array is empty.

October 20, 2023
10:33, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

Please define what you mean by “parent node”. See Matti’s answer above. The closest OPC UA ReferenceTypes that would model these are Identifiers.HasChild or Identifiers.Aggregates, but note that once you reach a “top-lvl-node”, that wont have a “parent”. It should have inverse hierarchical references though, such as Organizes.

Can you verify the ReferenceType between “this node” and the “parent node” via https://www.prosysopc.com/products/opc-ua-browser/?

If you use Identifiers.HierarchicalReferences, then it should get all hierarchical references (to that direction), which covers all of the abovementioned referecetypes as it also finds subtypes.

P.S.
Technically the client-side SDK only shows data it has received from the server. See near the end of https://reference.opcfoundation.org/Core/Part3/v104/docs/5.3.2 “Although not required, it is recommended that all hierarchical References be instantiated as bidirectional to ensure browse connectivity.”, thus technically it is possible (but not recommended) that e.g. a server would only provide the reference when browsing from the “parent node”.

If the server was made with our SDK, then it has bidirectional references. If not (and I guess anyway), https://www.prosysopc.com/blog/opc-ua-wireshark/ could be used to validate what the server does send. Or you could do a client.getAddressSpace().browse as well (note that some convenience methods do not take a BrowseDirection and the default is BrowseDirection.Forward unless set via setBrowseDirection(..)). In case you wonder, SDK itself (at least in anything modern versions) doesn’t use that convenience method when it Browses for .getNode (thus the default BrowseDirection should have no effect on that).

October 20, 2023
12:38, EEST
Avatar
Jeremy Morgan
Member
Members
Forum Posts: 15
Member Since:
November 6, 2019
sp_UserOfflineSmall Offline

Thanks for your reply.

The OPC server type we are most likely to connect to is Kepware, but it could be any other type too.

In my application I am dealing only with FolderType nodes which may have one or more Folder or Variable types as child components.

I’m using the Prosys OPC UA Browser app as a tool whilst working on this.

In the Reference section the Folders have:
HasTypeDefinition: FolderType
Organizes (x N): Other sub-folders
HasComponent (x N): Variables in this particular folder

In the Reference section the Variables have:
HasTypeDefinition: BaseVariableType

All of the references above are in the Forward direction. If I change the Browser direction to ‘Inverse’ then I get ‘No content in table’ for the both Folders and Variables alike.

The aim of the module I’m writing is that if I am passed a NodeId, to be able to construct the ‘Folder browse path’ to it. I understand that a Node might have several ‘parents’, but in this application it will be 99/100 that there will only be one ‘parent’ reference. If there is more than one then I will simply indicate that.

It looks like the Kepware server does not supply the Inverse references hence explaining why the array is empty – is my understanding correct? Does that mean that with this particular OPC server (Kepware), it is not possible to browse in the Inverse direction? If that is the case is there any way to implement what I am trying to achieve?

Thanks

October 20, 2023
13:28, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Just to be sure, can you also check with https://www.unified-automation.com/products/development-tools/uaexpert.html just to rule out it wouldn’t be something specific to our SDK. If that doesn’t either show them, then it is very likely that the server doesn’t support inverse references here. In that case I’m afraid there aren’t any good options. Most likely the best option would be to contact the server manufacturer and hope they can add them. I guess you can also technically Browse from a known node in the forward direction and try to find the the node this way. But, if you must start e.g. from the ‘Objects’ folder then it can be a pain.

Also, I must note that that kind of an address space is very basic. Thus do not expect every OPC UA Server out there be like that.

P.S.
It is also technically an error if the server HasTypeDefinition points to BaseVariableType, that is an abstract type (https://reference.opcfoundation.org/Core/Part5/v105/docs/7.2). Instead the most basic one is BaseDataVariableType (https://reference.opcfoundation.org/Core/Part5/v105/docs/7.4).

October 20, 2023
14:52, EEST
Avatar
Jeremy Morgan
Member
Members
Forum Posts: 15
Member Since:
November 6, 2019
sp_UserOfflineSmall Offline

Thanks for the suggestions, it is all making more sense now.

I checked with the UA Expert browser, and it is the same, so it looks like Inverse references are not supported/provided by the Kepware server I am testing on.

My application has to support a variety of OPC server types, so we cannot rely on special configurations, and as you say the requirement for Inverse references seems to be optional anyway, and therefore cannot be relied on.

I think maybe the only way to acheive this would be some kind of browse tree generator that runs in the background and caches the paths to the nodes. As it does not appear to be a trivial task and is ‘expensive’, it may be that we decide not to try to implement it anyway, as it was more of a ‘nice to have’ feature rather than a necessity.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
26 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 77

ibrahim: 76

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

fred: 41

Member Stats:

Guest Posters: 0

Members: 680

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6260

Newest Members:

sagarchau, elviralangwell4, Donnavek, Eddiefauth, DonaldPooma, fidelduke938316, Jan-Pfizer, DavidROunc, fen.pang@woodside.com, aytule

Moderators: Jouni Aro: 1009, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 983, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 321, Lusetti: 0, Ari-Pekka Soikkeli: 5

Administrators: admin: 1