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: 983
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: 983
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: 518

Currently Online:
25 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 77

Ibrahim: 76

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

fred: 41

Member Stats:

Guest Posters: 0

Members: 681

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6261

Newest Members:

graciela2073, sagarchau, elviralangwell4, Donnavek, Eddiefauth, DonaldPooma, fidelduke938316, Jan-Pfizer, DavidROunc, fen.pang@woodside.com

Moderators: Jouni Aro: 1010, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 983, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 321, Lusetti: 0, Ari-Pekka Soikkeli: 5

Administrators: admin: 1