writing complete data block at once with byte array

Questions regarding the use of the C++ SDK for Server or Client development or integration into customer products ...

Moderator: uasdkcpp

Post Reply
WolfgangFischer
Jr. Member
Jr. Member
Posts: 2
Joined: 25 Jan 2018, 14:24

writing complete data block at once with byte array

Post by WolfgangFischer »

We have an "old" OPC DA application which handles data transfer from PLC to server application and back. For that we read and write complete S7 data blocks, independent of their structure, using byte arrays.
We cannot change the server application. So I have to do the same job with OPC UA.
Using the C++ OPC UA SDK I am able to do the read functionality. After reading the value I use the extension object binary method to get a OpcUa_ByteString. This byte string I can convert into a byte array.
How can I write this byte array back into the PLC?

User avatar
Support Team
Hero Member
Hero Member
Posts: 3070
Joined: 18 Mar 2011, 15:09

Re: writing complete data block at once with byte array

Post by Support Team »

Hello WolfgangFischer,

as I understand you expose a Variable in the AddresSpace of DataType ByteArray (or ByteString - doesn't really make a difference) and allow a client to read and write the value of that Variable.
When the client is reading the Variable you read an S7 data block and return that ByteArray to the client. That part already works.

When the client is writing the Variable you need to write that ByteArray to an S7 data block.
How can I write this byte array back into the PLC?
What exactly is your question? What part is missing?
Best regards
Unified Automation Support Team

WolfgangFischer
Jr. Member
Jr. Member
Posts: 2
Joined: 25 Jan 2018, 14:24

Re: writing complete data block at once with byte array

Post by WolfgangFischer »

Hello,
That is not really the question. We do not expose a variable of data type byte array. This would be too simple :-). The S7 data block configured by STEP7/TIA is complex with hierarchical data structures to be used by the PLC programmers. Our application is only a data transport tool and has to transport the complete data block without any information about its structure. There is also no need for our application to know this structure. More over we cannot change the logic of the server application which expects a byte array. When I address die complete data block for reading I get an array of extension objects where I can get the byte array from Body.binary(). Now I like to write this (eventually changed) data back into the data block.

User avatar
Support Team
Hero Member
Hero Member
Posts: 3070
Joined: 18 Mar 2011, 15:09

Re: writing complete data block at once with byte array

Post by Support Team »

Hello Wolfgang,

you assume that the binary representation of the structure on your S7 data block and the binary content of the ExtensionOject is the same. This assumption is not correct.
Your approch may work by chance for a simple structure but will not savely work for complex structures / or certain DataTypes (e.g. DateTime).
That means the ByteArray you extract from the ExtensionObject may look different from what you got when reading the ByteArray in your old OPC DA application.

If you can't change your application and just want to transfer a ByteArray you need to provide a simple ByteArray in the server that contains the exact same data as in the OPC classic version. Like that you could leave the rest of your application untouched.
If you want to work with the ExtensionObject and modify the content of the ExtensionObject you need to know exactly how the Structure looks like.
Does a generic client (e.g. UaExpert) display the structure correctly?
If yes - the server already provides all the information you need on the client side to work with generic strucure values. For that case your UA Client application would need to encode the data to a ByteArray using the same encoding as your S7 data block has.
Best regards
Unified Automation Support Team

Post Reply