Find path to node in Address Space based on NodeId

Questions regarding the use of the C++ SDK for Server or Client development or integration into customer products ...

Moderator: uasdkcpp

Post Reply
mtu
Jr. Member
Jr. Member
Posts: 1
Joined: 26 Jul 2018, 09:49

Find path to node in Address Space based on NodeId

Post by mtu »

Hi

I'm using UA SDK C++ Bundle 1.7.1.

How do I have a NodeID to find the location of the node in the Address Space tree?

I have NodeID e.g. "ns=2;s=Demo.Dynamic.Scalar.Double"
wanted result: "Root/Objects/Demo/001_Dynamic/Scalar/Double"

thanks in advance.

sxdev
Full Member
Full Member
Posts: 7
Joined: 25 Mar 2020, 09:07

Re: Find path to node in Address Space based on NodeId

Post by sxdev »

Hi,

You can get the "parent" of a node by doing an inverse browse. Then you will have to do this recursively until there is no parent anymore. To build a path of browse names you will first have to read the browse name of the source node.

Code: Select all

// Pseudo code
path = session.read(Node = sourceNodeId, AttributeId = OpcUa_Attributes_BrowseName)
parent = sourceNodeId
while (true)
{
  BrowseContext ctx
  ctx.referenceTypeId = OpcUaId_HierarchicalReferences
  ctx.browseDirection = OpcUa_BrowseDirection_Inverse
  ctx.resultMask = OpcUa_BrowseResultMask_BrowseName
  ctx.includeSubtype = OpcUa_True
  
  ref =  session.browse(parent, ctx)
  if (ref == NULL)
  {
    break;
  }
  
  path = ref.BrosweName + "/" + path
  parent = ref.NodeId
}

ABakhsh
Jr. Member
Jr. Member
Posts: 1
Joined: 21 Jun 2022, 13:05

Re: Find path to node in Address Space based on NodeId

Post by ABakhsh »

Find code snippets in any language https://codeprozone.com
Its a developer’s community where programmers and developers from the globe share the codes and many can learn from their experiences. Here codes are shared written by Master Coders and many follow their pattern. These codes help developers to grow and be at home in their skills. By using these codes, a developer can develop their projects faster, can easily understand and may have more chances to boom in their field.

Post Reply