Calling UaBase_CreateNumericNodeIdEx() required?

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

Moderator: uasdkc

Post Reply
JeromeBos
Sr. Member
Sr. Member
Posts: 14
Joined: 09 May 2016, 15:31

Calling UaBase_CreateNumericNodeIdEx() required?

Post by JeromeBos »

Do I need to call UaBase_CreateNumericNodeIdEx() each time I want to reset a OpcUa_NodeId or can I simply reset the member-variables?

Here is an example to provide some context regarding my question. Is the first option valid? Which option would be best to use?

Option 1:

Code: Select all

void some_function()
{
    OpcUa_NodeId referenceTypeId;
    UaProvider_Poss_NodeInfo nodeInfo;

    /* Initialize */
    ...
    OpcUa_NodeId_Initialize(&referenceTypeId);
    UaProvider_Poss_NodeInfo_Initialize(&nodeInfo);
    ...

    /* Create node */
    ...
    referenceTypeId.Identifier.Numeric = OpcUaId_Organizes;
    referenceTypeId.NamespaceIndex = 0;
    nodeInfo.NodeId.Identifier.String = "MainNode id";
    nodeInfo.NodeId.NamespaceIndex = 0;
    ...
    uStatus = UaProvider_Poss_CreateNode(pAddressSpace,&pNode,pParent,&referenceTypeId,&nodeInfo);
    ...

    /* Create some sub-node */
    ...
    referenceTypeId.Identifier.Numeric = OpcUaId_HasComponent;
    referenceTypeId.NamespaceIndex = 0;
    nodeInfo.NodeId.Identifier.String = "SubNode1 id";
    nodeInfo.NodeId.NamespaceIndex = 0;
    ...
    uStatus = UaProvider_Poss_CreateNode(pAddressSpace,&pNode,pParent,&referenceTypeId,&nodeInfo);
    ...

    /* Create another sub-node */
    ...
    referenceTypeId.Identifier.Numeric = OpcUaId_HasComponent;
    referenceTypeId.NamespaceIndex = 0;
    nodeInfo.NodeId.Identifier.String = "SubNode2 id";
    nodeInfo.NodeId.NamespaceIndex = 0;
    ...
    uStatus = UaProvider_Poss_CreateNode(pAddressSpace,&pNode,pParent,&referenceTypeId,&nodeInfo);
    ...
}
Option 2:

Code: Select all

void some_function()
{
    OpcUa_NodeId referenceTypeId;
    UaProvider_Poss_NodeInfo nodeInfo;

    /* Initialize */
    ...
    UaProvider_Poss_NodeInfo_Initialize(&nodeInfo);
    ...

    /* Create node */
    ...
    UaBase_CreateNumericNodeIdEx(&referenceTypeId, OpcUaId_HasComponent, 0);
    UaBase_CreateStringNodeIdEx(&nodeInfo.NodeId, "MainNode id", 0);
    ...
    uStatus = UaProvider_Poss_CreateNode(pAddressSpace,&pNode,pParent,&referenceTypeId,&nodeInfo);
    ...

    /* Create some sub-node */
    ...
    UaBase_CreateNumericNodeIdEx(&referenceTypeId, OpcUaId_HasComponent, 0);
    UaBase_CreateStringNodeIdEx(&nodeInfo.NodeId, "SubNode1 id", 0);
    ...
    uStatus = UaProvider_Poss_CreateNode(pAddressSpace,&pNode,pParent,&referenceTypeId,&nodeInfo);
    ...

    /* Create another sub-node */
    ...
    UaBase_CreateNumericNodeIdEx(&referenceTypeId, OpcUaId_HasComponent, 0);
    UaBase_CreateStringNodeIdEx(&nodeInfo.NodeId, "SubNode2 id", 0);
    ...
    uStatus = UaProvider_Poss_CreateNode(pAddressSpace,&pNode,pParent,&referenceTypeId,&nodeInfo);
    ...
}

User avatar
Support Team
Hero Member
Hero Member
Posts: 3068
Joined: 18 Mar 2011, 15:09

Re: Calling UaBase_CreateNumericNodeIdEx() required?

Post by Support Team »

Hello,

In your example, 'Option 2' is the preferred one, as UaBase_Create<Type>NodeIdEx() ensures that all fields of the OpcUa_NodeId structure are set correctly and consistently. Also, you only need one line of code instead of three.

It is important that the 'IdentifierType' is set appropriately, depending on which of the _Identifier union's members was set. This is wrong in your 'Option 1' example, here you would need to set 'nodeInfo.IdentifierType' to 'OpcUa_IdentifierType_String', as your intent is to create a string NodeId (OpcUa_NodeId_Initialize() sets the 'IdentifierType' to 'OpcUa_IdentifierType_Numeric').
Best regards
Unified Automation Support Team

JeromeBos
Sr. Member
Sr. Member
Posts: 14
Joined: 09 May 2016, 15:31

Re: Calling UaBase_CreateNumericNodeIdEx() required?

Post by JeromeBos »

Support Team wrote: In your example, 'Option 2' is the preferred one, as UaBase_Create<Type>NodeIdEx() ensures that all fields of the OpcUa_NodeId structure are set correctly and consistently. Also, you only need one line of code instead of three.
Thanks for the clarification.
Support Team wrote: It is important that the 'IdentifierType' is set appropriately, depending on which of the _Identifier union's members was set. This is wrong in your 'Option 1' example, here you would need to set 'nodeInfo.IdentifierType' to 'OpcUa_IdentifierType_String', as your intent is to create a string NodeId (OpcUa_NodeId_Initialize() sets the 'IdentifierType' to 'OpcUa_IdentifierType_Numeric').
I see, slight oversight from my part. Thanks for pointing it out.

Post Reply