Writing serialized arrays as ExtensionsObjects with different lengths|OPC UA Implementation: Stacks, Tools, and Samples|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
Writing serialized arrays as ExtensionsObjects with different lengths
Avatar
Matthias Reiseder
New Member
Members
Forum Posts: 2
Member Since:
09/19/2019
sp_UserOfflineSmall Offline
1
09/19/2019 - 07:59
sp_Permalink sp_Print

Hello,

to quickly read from and write data to an OPC UA server (which is out of my control) I'm currently using structured values instead of single Nodes. The serialization and deserialization of the data is handled in my C# code.

Writing an ExtensionObject with the exact same size as the value on the server works fine.

My problem are ExtensionObjects with a different size be it smaller or larger as on the server. The write requests come back with the "BadEndOfStream" status code.

Is there something I need to do to tell the write request that an object with different size will be sent?

This could also very likely be an issue with the server implementation, as of now I haven't confirmed that and debugging/stepping through the OPC UA Reference source code did not help very much.

Any help/advice would be very appreciated.

Have a great day!

Avatar
Randy Armstrong
Admin
Forum Posts: 1451
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
09/19/2019 - 11:46
sp_Permalink sp_Print

ExtensionObjects are variable length. If you get this error it is because there is error in the encoding or decoding.

How are you serializing the ExtensionObject?

Avatar
Matthias Reiseder
New Member
Members
Forum Posts: 2
Member Since:
09/19/2019
sp_UserOfflineSmall Offline
3
09/19/2019 - 23:50
sp_Permalink sp_Print

When I read the ExtensionObject and deserialize the byte array everything works as expected. To check if the serialization works I serialized the data I got from the ExtensionObject and get the exact same byte array. I'm assuming the serialization works because writing this ExtensionObject with the same size works and the write request goes through with status code "Good".

I am dynamically serializing C# objects into their byte array representation so I can send them to a PLC rather quickly instead registering and configuring multiple nodes.

The only problematic variables are strings because they vary in length. This is why my ExtensionObjects have different sizes.

Serialization for objects without strings works in both ways as expected.

Avatar
Randy Armstrong
Admin
Forum Posts: 1451
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
4
09/20/2019 - 06:04
sp_Permalink sp_Print

If you are using the built in BinaryEncoder to do the serialization then it is likely a bug in the server.

If you are using your own code to do the encoding then you may be putting the wrong bytes on the wire.

Using your code to decode what your code writes does not show that the encoding on the wire is correct.

The error sounds like a length in the stream is not being encoding correctly.

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 21
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1351
Posts: 4579