How to check a Node's UAVariable DataType in C++ code

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

Moderator: uasdkcpp

Post Reply
er.raunakgupta
Hero Member
Hero Member
Posts: 37
Joined: 11 May 2017, 09:26

How to check a Node's UAVariable DataType in C++ code

Post by er.raunakgupta »

Hi All,

I have a data model of which one node is defined below:

Code: Select all

<UAVariable DataType="ConnectionStatusEnumerationType" Historizing="true" ParentNodeId="ns=1;i=1003" NodeId="ns=1;i=15492" BrowseName="1:ConnectionState" UserAccessLevel="5" AccessLevel="5">
        <DisplayName Locale="en">ConnectionState</DisplayName>
        <References>
            <Reference ReferenceType="HasTypeDefinition">i=63</Reference>
            <Reference ReferenceType="HasComponent" IsForward="false">ns=1;i=1003</Reference>
            <Reference ReferenceType="HasModellingRule">i=78</Reference>
        </References>
        <Value>
            <uax:Int32>1</uax:Int32>
        </Value>
</UAVariable>
I have a list of Nodes in a vector:

Code: Select all

std::vector<UaNode*> targetNodes
I need to know the Node's UAVariable DataType (as given above in the XML data model). For example Browsename = "ConnectionState" is of DataType="ConnectionStatusEnumerationType". How could I check the datatype in the C++ SDK code?
Waiting for your response. Thanks!
Regards
rG

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

Re: How to check a Node's UAVariable DataType in C++ code

Post by caspervanzoest »

Hi rG,

The datatype is stored into struct OpcUa_Variant.

The folowing code gives the corresponging enum value of the datatype:

Code: Select all

std::vector<UaNode*> targetNodes;
OpcUa_DataVariable* pVariable = (OpcUa_DataVariable*)targetNodes.at(/*INDEX*/);
OpcUa_Variant* myVariant = OpcUa_Variable_GetValue(pVariable);
OpcUA_Byte myType = myVariant->Datatype;
Hope this helps.

Best Regards,
Casper

er.raunakgupta
Hero Member
Hero Member
Posts: 37
Joined: 11 May 2017, 09:26

Re: How to check a Node's UAVariable DataType in C++ code

Post by er.raunakgupta »

Hi Casper,
The below code is compiling an error.

Code: Select all

    OpcUa_DataVariable* pVariable = (OpcUa_DataVariable*)targetNodes.at(/*INDEX*/);
    OpcUa_Variant* myVariant = OpcUa_Variable_GetValue(pVariable);
    OpcUA_Byte myType = myVariant->Datatype;
Because, object type OpcUa_DataVariable and OpcUa_Variable_GetValue does not seems to exist in C++ SDK. Could you explain what am I missing?

Br/
rG

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

Re: How to check a Node's UAVariable DataType in C++ code

Post by Support Team »

Hello er.raunakgupta,

if you already keep a list of UaNodes maybe you want to keep a list of UaVariables for that purpose.

To check the DataType of a UaVariable you can use the getter method dataType(). See:
http://documentation.unified-automation ... 422d2caa50
Best regards
Unified Automation Support Team

Post Reply