How to read variable type

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

Moderator: uasdkcpp

Post Reply
KnightChang
Hero Member
Hero Member
Posts: 32
Joined: 19 Feb 2016, 09:01

How to read variable type

Post by KnightChang »

Dears,

I need to get Variable DataType if the node is write only.

But if I try to read by DataType AttributeId , why will it always return DataType_NodId ?

please see the code as following :

nodesToRead[0].AttributeId = OpcUa_Attributes_DataType;

result = m_pSession->read(
serviceSettings,
0,
OpcUa_TimestampsToReturn_Both,
nodesToRead,
values,
diagnosticInfos);

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

Re: How to read variable type

Post by Support Team »

Hello KnightChang,

this is the intendend way to read the DataType and there is no other way to read the DataType.
What you actually get back is the NodeId of the DataType Node in the type system.

You find all DataType nodes if you browse into Types->DataTypes->BaseDataType:
e.g. Double has the numeric NodeId 11.

Since all the numeric identifiers of DataType nodes in namespace 0 are well known you can build your application logic on top of that.
The SDK provides defines for all well known types and for all BuiltInTypes:
e.g. OpcUaType_Double = 11
It is recommended to use those defines in the code instead of working with numeric identifiers directly.

The documentation provides some background information about OPC UA concepts:
http://documentation.unified-automation ... ntals.html

For further details and understanding you can read on in the OPC UA specification Part 3, 4 and 5. These are available for free on the OPC Foundation website:
https://opcfoundation.org/developer-too ... chitecture
Best regards
Unified Automation Support Team

KnightChang
Hero Member
Hero Member
Posts: 32
Joined: 19 Feb 2016, 09:01

Re: How to read variable type

Post by KnightChang »

Hi Support Team,

I found the answer, many thanks. ;)

lorenzodelpino
Full Member
Full Member
Posts: 9
Joined: 20 Feb 2017, 09:41

Re: How to read variable type

Post by lorenzodelpino »

Ok, but I don't understand how to get the datatype attribute if the node is Write Only

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

Re: How to read variable type

Post by Support Team »

lorenzodelpino,

if the AccessLevel is Writeable only that means the Value Attribute can only be written.
Other Attributes like DataType can still be readable.
Best regards
Unified Automation Support Team

lorenzodelpino
Full Member
Full Member
Posts: 9
Joined: 20 Feb 2017, 09:41

Re: How to read variable type

Post by lorenzodelpino »

Support Team wrote:lorenzodelpino,

if the AccessLevel is Writeable only that means the Value Attribute can only be written.
Other Attributes like DataType can still be readable.
Ok, but if I try to read DataType Attribute , I always get OpcUaType_NodeId (17) instead the DataType of Variable.

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

Re: How to read variable type

Post by Support Team »

Hello lorenzodelpino,

this is a forum for technical questions about OPC UA and or SDK products. This is not a forum to get an introduction to the basic concepts of OPC UA.
The NodeId you get back when reading the DataType Attribute is the NodeId of the DataType Node in the TypeSystem.
A good starting point to get familiar with OPC UA is reading the specifications Part 3,4 and 5.
Best regards
Unified Automation Support Team

Post Reply