How to get the DataType of an UaNode?

948 views Asked by At

I am using the eclipse-milo`s jars, version 0.5.3.

I would like to read specific nodes, and store their values in a database. I intend to dynamically construct the database column, taking into consideration the data type. For example: a node of type Float (Identifiers.Float) would be a FLOAT in the database.

I can connect to an OPCUA Server, retrieve the AddressSpace and read the node value.

UaNode node = uaClient.getAddressSpace().getNode(nodeId);
DataValue dataValue = node.readAttribute(AttributeId.Value);
Object value = dataValue.getValue().getValue();

How can I read the type of the value of a given Node? In the above example, the datatype of node. I have tried the following:

Optional<ExpandedNodeId> dataType = dataValue.getValue().getDataType();        
if (dataType.isPresent()) {
    ExpandedNodeId nodeDataType = dataType.get();
    nodeDataType.getIdentifier();
}

The identifier of the data type is received (ns=0;i=10), but not the type.

2

There are 2 answers

0
Kevin Herron On BEST ANSWER

DataType's in OPC UA are identified by a NodeId, so what you're seeing is normal.

If you need assistance resolving a datatype to a "backing" class you might look at the DataTypeTree class for assistance:

https://github.com/eclipse/milo/blob/master/opc-ua-sdk/sdk-core/src/main/java/org/eclipse/milo/opcua/sdk/core/DataTypeTree.java

https://github.com/eclipse/milo/blob/master/opc-ua-sdk/integration-tests/src/test/java/org/eclipse/milo/opcua/sdk/core/DataTypeTreeTest.java


DataTypeTree tree = DataTypeTreeBuilder.build(client);

UaVariableNode currentTimeNode = client.getAddressSpace()
    .getVariableNode(Identifiers.Server_ServerStatus_CurrentTime);

NodeId dataType = currentTimeNode.getDataType();

Class<?> clazz = tree.getBackingClass(dataType);

System.out.println(clazz); // class org.eclipse.milo.opcua.stack.core.types.builtin.DateTime
0
Jordy On

This isn't a solution, however maybe it's worth checking out the Identifiers class. This class contains the OPC UA data types and creates a NodeId based on the id value of the data type. You could write a class that reverses this process and finds the data type based on the id value.

There might be a better solution, but I haven't been using Eclipse Milo for that long, so currently I wouldn't know.