Page 1 of 1

Find path to node in Address Space based on NodeId

Posted: 13 May 2022, 12:18
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.

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

Posted: 19 May 2022, 13:05
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
}

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

Posted: 21 Jun 2022, 13:09
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.