

16:43, EEST

June 12, 2018

Following Scenario:
I receive binary data as byte[] arrays. In my implementation I convert this byte[] arrays to the corresponding datatype objects of the OpcUa Nodes, creating a variant, then a datavalue and writing them to the OpcUa server.
Cause of the requirement to handle more data types, in my implementation as byte[] arrays, there is the question if the conversation of the data from byte[] array to the target datatype can be done by the SDK.
I played a little bit whith the client.getAddressSpace().getDataTypeConverter().convert(…) method, but wasnt able to convert my byte[] arrays to the target datatypes.
Is it even possible, to convert the byte[] array data by the SDK or do I have to do this by my own….
Thanks Alex
18:17, EEST

April 3, 2012

Hi,
The Java type byte[] does not currently map to any UA type.
What is your UA DataType, i.e. the DataType Attribute value NodeId of the node where you are writing?
Assuming it would be the UA DataType ByteString, you would write a new Variant(ByteString.valueOf(your_byte[]_variable))
Also your question is a bit .. unclear, do you have a data format specified for your byte[] data? If you can explain your use-case in bit more detail it would be easier to help. But yes, in general you need to convert your own data formats.
Also please see https://forum.prosysopc.com/forum/opc-ua-java-sdk/convert-input-string-1-2-3-4-5-to-variant-array-datatype
12:50, EEST

June 12, 2018

Ok, i will specify a little bit more:
I getting several byte[] arrays. For example, one of them is a String, the next one INT32, next one UInt16…..
The byte[] array is part of a class, with additional information (DataType, OpcUa Path, NodeID of the Server)
At the moment, i convert the byte[] array to the matching class (INT32, String,…..) as an new object
Then creating a variant with this object, and writing as DataValue to the OpcUa Server.
My question is, is there a build in way, to convert the data….
16:25, EEST

April 3, 2012

Hi,
That still does not answer the question on how your byte[] data format is defined, i.e. what are the encoding rules for it (as an example, in general, there are more one way to encode a String, one could prefix the length OR use a NULL i.e. ASCII 0 null terminator)
IF (and only IF) the byte[] contains data based on the encoding rules of OPC UA as described in the UA specification Part 6, then this would work
BinaryDecoder dec = new BinaryDecoder(data);
UaType type = client.getAddressSpace().getType(NodeId of type);
Class<?> clazz = type.getJavaClass();
Object javaObject = dec.get(null, clazz);
Variant v = new Variant(javaObject);
However if the byte[] contains some other (unknown) format, then there is no magical way for the SDK to know about it and you need to do it yourself.
Most Users Ever Online: 1919
Currently Online: Guido Niewerth
53 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: 803
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1538
Posts: 6493
Newest Members:
rebekahfortner3, Stevennox, qfpalfie08, brittny89u, LinwoodBup, isabellabeeton2, ladonnacdv, DarwinVew, betseymitford95, HowardtitModerators: Jouni Aro: 1027, Pyry: 1, Petri: 0, Bjarne Boström: 1037, Jimmy Ni: 26, Matti Siponen: 353, Lusetti: 0
Administrators: admin: 1