Reputation: 3
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.
Upvotes: 0
Views: 1181
Reputation: 7015
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:
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
Upvotes: 0
Reputation: 1
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.
Upvotes: 0