12:53, EET
November 16, 2015
Hello everybody,
I’ve got the job to program a opc-ua client for an existing machine interface. At that I have to read the value from a node that has a complex data type. For this I use a code similar to
…
nodeId = new NodeId(2, “Measurements”);
DataValue dv = client.readValue(nodeId));
System.out.println(dv.getValue());
…
Furthermore I found that it is possible to get a instance of an ‘ExtensionObject’
ExtensionObject eo = (ExtensionObject) (dv.getValue().getValue());
But now I do not know how I can evaluate the data further. As usual with complex data the structure of the content is not simple but consists of nested arrays of further complex sturctures.
With the common OPC UA Client from Prosys I also cannot further investigate the data, I only see that there is a object of the type ExtensionObject.
On the other hand it is possible to investigate the data with the free Softing OPC UA client (I know that the machine OPC UA server is build using the Softing SDK…). With this tool it is possible to drill into the arrays and the containing complex structures. Therefore, it seems to me to be possible in principle.
I have only found the document ‘Using Complex DataTypes’ from Otso Palonen, but I don’t understand how to adapt this example to my problem.
Are there any other sources I can use? Is it possible in principle to develop a Java Client with the Prosys SDK and complex data types for an existing OPC UA server that is developed in an other tool set?
Thanks for any advice
Michael
8:17, EET
April 3, 2012
ExtensionObject in most cases means the data is as (java) byte[]. This could happen if we do encounter unknown type, i.e. one for which we do not have a serializer. If this happens you will get info level log from the stack level (org.opcfoundation.ua.encoding.binary.BinaryDecoder) “Failed to decode ExtensionObject …” The sample programs that come in the SDK bundle by default have stack level only as error, see log.properties file.
What is the DataType of that Node?
In case that is from the Device Information model (the “di” in the package name), you need to call UaClient.registerModel(com.prosysopc.ua.types.di.client.MODEL). Similar ones are “plc” for PLCopen and “adi” for “OPC UA for Analyzer Devices” but they do not seem to contain any complex types (also there is the “opcua” for the standard model, this is always loaded).
In case that is from another model, if you have the NodeSet2 format XML file for the model, you can use the codegenerator in the SDK to create java types for the complex data types (remember to load the model like above).
If those wont work, you need to create the Serializer for that datatype. You need to know which fields are in that complex type and in which order. Probably the easiest is to look at the SampleTypes.xml in the codegen sample and try to adapt that.
– Bjarne
17:08, EET
November 16, 2015
The question “What is the DataType of that Node?” seems simple, but to be honest, I’m not sure.
I find no way to detect the datatype of the node in the application. Do you have a code snippet for this? Your OPC UA Client displays the Datatype ‘Structure’. The Softing Client shows a Datatype that seems to reference a Node in the namespace /Types/DataTypes/OPCBinary. If it helps I can send you screenshots of the Clients.
My next try was to generate java code to decode the binary data. I received a XML format file that should describe the datatype, but again, I’m not sure if the XML file is valid (can be provided). At least the codegen task throws an Exception (Exception in thread “main” java.lang.IllegalArgumentException: No method in multimethod ‘parse-nodeid’ for dispatch value: null)
Michael
9:07, EET
April 3, 2012
DataType: It is the DataType Attribute of that node. It defines the type for the Value Attribute (note that as with object oriented programming languare, you can put sub-types to it too). To check it you can use e.g. the following snippet:
NodeId nodeId = (NodeId for the node)
UaClient client = (the client)
DataValue dv = client.readAttribute(nodeId, Attributes.DataType); //org.opcfoundation.ua.core.Attributes
dv.getValue().toString();
‘Structure’ is the supertype for all complex datatypes.
“The Softing Client shows a Datatype that seems to reference a Node in the namespace /Types/DataTypes/OPCBinary.”
Hmm.. usually it should point to Types/DataTypes/BaseDataType/Structure/??? if it is a complex type.
The schema for the NodeSet2 format should be https://opcfoundation.org/UA/2011/03/UANodeSet.xsd
– Bjarne
Most Users Ever Online: 1919
Currently Online:
19 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 88
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 730
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1529
Posts: 6471
Newest Members:
rickykennion, PromotionToold, HypromeImpupe, toneylapham544, rondawolinski7, Marypof5711, roycedelargie91, kourtneyquisenbe, ellis87832073466, zkxwilliemaeModerators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0
Administrators: admin: 1