Hello, I’m currently implementing a device driver and using ManagedAddressSpaceFragmentWithLifecycle.write as part of it. I need the datatype that the WriteValue holds to properly encode my write to a device, but when I try to write to an integer tag, the datatype I get when I go through the chain of WriteValue.getValue().getValue().getDataType().get() is a string. Is this the correct chain of calls I should be using?
Yes, that means the client is trying to actually write a String for some reason.
Where is your write originating from? Quick Client? Designer? External client?
First thing I'd check is whether a read for the DataType attribute of the Node you're trying to write to returns the DataType you expect or returns String.
Hi Kevin, I’m doing this in the designer. I have a logger statement in my AddressSpaceComposite.onDataItemsCreated method, and I iterate through my List. From the call DataItem.getReadValueId().getNodeId().getType(), I see it’s a string, even though the tag in the designer is an integer.
The tag in the Designer is irrelevant. Your driver implementation is at some point responsible for setting the OPC UA DataType on that Node. If you're using the Managed stuff then you would have set it when you built the Node and added it to the node manager.
Hi Kevin,
I don’t think I am at the moment for this situation. The situation I’m seeing this is when I’m manually addressing and creating a new tag, and not from dragging and dropping from the tag browser. My current implementation is to run some code in onDataItemsCreated and then call SubscriptionModel.onDataItemsCreated. Is the node generated different when I create it this way?
When/where do you build the UaNode instances?
I’m building them in 2 spots. First is ManagedAddressSpaceFragmentWithLifecycle.onStartup. We build nodes based on definitions in a config file, and either a UaFolderNode is added or a UaVariableNode is added. The other spot is ManagedAddressSpaceFragmentWithLifecycle.browse, when those folder nodes are accessed through the tag browser. When those folders are accessed, only then are the child nodes built.
Well pay attention to the DataType you set in those spots.
When Ignition's OPC UA client writes a Value it first reads the DataType attribute and then uses that to cast the value, if necessary, into the type expected by the server.
If you're receiving a String value then it's because responded to that read for the DataType attribute and said it was a String.
This seems to be a different question/observation than the original, which was about writes.
You're calling NodeId::getType, which is telling you the type of identifier used by the NodeId is String. This is unrelated to the DataType of the Node.
You won't ever get to know how the tag in the Ignition Designer is configured. Your driver is a fragment of an OPC UA server address space. It decides what DataType a Node is. These are completely independent systems.
When you drag and drop a tag from the OPC Browser into the Tag Browser in the Designer, it sets the type of that tag based on the DataType attribute it read while browsing. It's not the other way around.