Variable getting Enum datatype

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

Variable getting Enum datatype

Post by er.raunakgupta »

Hi All,

I am working with server development based on UA SDK. I have a variable "Connectionstate"defined in my data model under an Enum DataType:

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>
The problem which I am facing is that variable ConnectionState value is of type <uax:Int32>1</uax:Int32> but when I drag it in UaExpert I see the dataType as "Byte" which is from source (taking raw value, not modifying accoriding to model). I don't see exactly why it is not changed to Int32. The only thing which I found out is the below code which returns Enum datatype NodeId= "3013" for my ConnectionState variable.

Code: Select all

std::vector<UaNodeId> Server::getDatatypesForNodes(const std::vector<UaNode*>& nodes)
{
    std::vector<UaNodeId> dataTypes;

    for (unsigned int i = 0; i < nodes.size(); i++)
    {
        UaDataValue uaDataValue;

        UaNodeId dataTypeNodeId;

        nodes[i]->getAttributeValue(NULL, OpcUa_Attributes_DataType, uaDataValue);

        UaVariant datatype(*uaDataValue.value());

        datatype.toNodeId(dataTypeNodeId);

        dataTypes.push_back(dataTypeNodeId);
    }
    return dataTypes;
}
<Alias Alias="ConnectionStatusEnumerationType">ns=1;i=3013</Alias>
Where exactly could be the problem? Is there a way I can check, that the Node id is of datatype Enum and then change it according to data model (i.e. into Int32). If any idea on this, please help.
Thanks and best regards
rG

Post Reply