UAServer - getting node from string-based nodeID?

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

Moderator: uasdkc

Post Reply
caspervanzoest
Full Member
Full Member
Posts: 8
Joined: 21 Oct 2016, 14:12

UAServer - getting node from string-based nodeID?

Post by caspervanzoest »

I am trying to connect my dataVariables into a tree structure. the nodeID'S are identifier type 'String', not 'Numeric'.

When getting a parent node from a numeric ID, everything goes well:

Code: Select all

       /* Get parent node */
       UaServer_AddressSpace_Get(0, &pServerAddressSpace);
       nodeId.NamespaceIndex = 0;
       nodeId.Identifier.Numeric = OpcUaId_ObjectsFolder;
       UaServer_GetNode(pServerAddressSpace, &nodeId, (OpcUa_BaseNode**)&pFolder);
       pParentNode = (OpcUa_BaseNode*)pFolder;

       /* Create node */
       uStatus = UaServer_CreateDataVariableS(pAddressSpace,
                                             &pVariable,
                                             pParentNode,
                                             p_FullName,
                                             g_uCustomProvider_NamespaceIndex,
                                             p_Name);
       OpcUa_GotoErrorIfBad(uStatus);
But when trying to find an parent node, from a String identified NodeID,
It does'nt seem to find any:

Code: Select all

       /* Get parent node, assuming  adddresspaceID is 4 in this example.  */
       nodeId.Identifier.String = *OpcUa_String_FromCString(p_Parent);
       UaServer_GetNode(&(g_pCustomProvider->AddressSpace), &nodeId, &pParentNode);

       // pParentNode is still OpcUa_Null, even then the node with given nodeID(String) 'p_Parent' exists on the server...
Also the following code, does not seem to work:

Code: Select all

       UaBase_CreateStringNodeId(&nodeId, p_Parent);
       pParentNode = UaServer_GetNodeById(&nodeId);

       // pParentNode is still OpcUa_Null, even then the node with given nodeID(String) 'p_Parent' exists on the server...
Is there an example of getting any NodeID with string-identifier, as a 'OPCUA_BaseNode*'?

Thanks in advance.

caspervanzoest
Full Member
Full Member
Posts: 8
Joined: 21 Oct 2016, 14:12

Re: UAServer - getting node from string-based nodeID?

Post by caspervanzoest »

Thanks for all the responses! ::)
Meanwhile I figured out what the problem was.
I will post it here so it might help others that might have the same question.

In order to get the Node from a String identifier, the nodeID to search for, should be in the same namespaceID as the one creating to search.
In this case, the costum provider adds the nodes to namespaceID '4'.
To find the Node in this address-space, we have to create the nodeID in the same NameSpaceID.

Code: Select all

             OpcUa_NodeId_Initialize(&nodeId);
             UaBase_CreateStringNodeIdEx(&nodeId, "NameToFind", 4); // 4 is the nsID in this case
             pParentNode = UaServer_GetNodeById(&nodeId);
Good luck with your

Post Reply