Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Write byte[] to OpcuUa Server directly without data conversation
June 12, 2018
16:43, EEST
Avatar
Alex78
Member
Members
Forum Posts: 3
Member Since:
June 12, 2018
sp_UserOfflineSmall Offline

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

June 12, 2018
18:17, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1032
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

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

June 13, 2018
12:50, EEST
Avatar
Alex78
Member
Members
Forum Posts: 3
Member Since:
June 12, 2018
sp_UserOfflineSmall Offline

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….

June 13, 2018
16:25, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1032
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

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

byte[] data = …;
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.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
15 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: 729

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1529

Posts: 6471

Newest Members:

rondawolinski7, Marypof5711, roycedelargie91, kourtneyquisenbe, ellis87832073466, zkxwilliemae, gabriellabachus, Deakin, KTP25Zof, Wojciech Kubala

Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0

Administrators: admin: 1