Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

Opc Ua ExtensionObject

More
22 Dec 2016 14:56 - 22 Dec 2016 15:00 #4703 by support
Replied by support on topic Opc Ua ExtensionObject
Oh, I see.

There are 2 options (I haven't actually tried them, but the principles should work):

1) You need to "tell" the compiler that it is dealing with an ExtensionObject, by typecasting the received value to Opc.Ua.ExtensionObject, and then you will get the data from its Body property. In order to make the type cast, however, you will need to reference the Opc.Ua.Core assembly, and here is where the necessity to select the installation of Embedded Assemblies comes to play. And, as a third execution step, you will need to type cast the value from Body to Byte[], because Body is an 'object'.

2) Or, you can do an equivalent of that, but without referencing the Opc.Ua.Core assembly, using .NET reflection: locate the "Body" property getter on the received value, and invoke it.


( A third option, for VB users only: It will probably work, with late binding, by simply accessing .Body property, because VB is not strong-typed as C#).

Regards
Last edit: 22 Dec 2016 15:00 by support.
The following user(s) said Thank You: hcvoort

Please Log in or Create an account to join the conversation.

More
22 Dec 2016 14:48 #4702 by hcvoort
Replied by hcvoort on topic Opc Ua ExtensionObject
Ok, I understand how I can use bitconverter. But from the EasyUAClient.read(endpoint, node, AttributeID=13) I get an extension object with a Byte[10] in there somewhere. How do I get it to a 'real' Byte[]? Then I can decode it. I hope you understand my explanation.

BR,

Carsten Voort

Please Log in or Create an account to join the conversation.

More
22 Dec 2016 14:27 #4701 by support
Replied by support on topic Opc Ua ExtensionObject
OK, then the 10 bytes are 4 bytes for each of the Float fields, and 2 bytes for the Int16 field.

According to OPC UA spec Part 6,

All floating point values shall be encoded with the appropriate X200 : ITU-T X.200 – Open
Systems Interconnection – Basic Reference Model
www.itu.int/rec/T-REC-X.200-199407-I/en

and

All integer types shall be encoded as little endian values where the least significant byte
appears first in the stream.


With .NET class BitConverter (msdn.microsoft.com/en-us/library/system.bitconverter(v=vs.110).aspx) and methods like ToSingle() and ToInt16(), it shouldn't be too difficult to decode it.

Please Log in or Create an account to join the conversation.

More
22 Dec 2016 14:14 #4700 by hcvoort
Replied by hcvoort on topic Opc Ua ExtensionObject
<opc:StructuredType Name="Zeef">
<opc:Field Name="Max_Spanmaat" TypeName="opc:Float"/>
<opc:Field Name="Min_Spanmaat" TypeName="opc:Float"/>
<opc:Field Name="ZeefType" TypeName="opc:Int16"/>
</opc:StructuredType>

Please Log in or Create an account to join the conversation.

More
22 Dec 2016 13:52 #4699 by support
Replied by support on topic Opc Ua ExtensionObject
Please post the XML description here.

Please Log in or Create an account to join the conversation.

More
22 Dec 2016 13:37 #4698 by hcvoort
Replied by hcvoort on topic Opc Ua ExtensionObject
Dear support,

I know the xml description but I cannot do anything with the Byte[10]. Since it is an extension object there is no way to cast it or extract any bytes using normal system methods. Does QuickOPC provide such methods?

BR,

Carsten Voort

Please Log in or Create an account to join the conversation.

More
22 Dec 2016 12:13 #4694 by hcvoort
Replied by hcvoort on topic Opc Ua ExtensionObject
Oke, I will dig into it.

BR,

Carsten Voort

Please Log in or Create an account to join the conversation.

More
22 Dec 2016 12:12 #4693 by support
Replied by support on topic Opc Ua ExtensionObject
You will need to read in, or otherwise obtain from the server side, the actual XML that described the data type. Having that, use OPC UA Spec Part 3 Annex 3, and Part 6 Mappings, to decode.

Please Log in or Create an account to join the conversation.

More
22 Dec 2016 12:06 #4692 by hcvoort
Replied by hcvoort on topic Opc Ua ExtensionObject
Oke, let's say that I receive this Extension object with Byte[10] as a value and I know that the structure at the PLC side is defined as follows:

STRUCT
ZeefType : INT; //2 bytes
Min_Spanmaat : REAL; //4 bytes
Max_Spanmaat : REAL; //4 bytes
END_STRUCT

which makes a total of 10 bytes. How can I decode the Byte[10]? Which methods do I use? Could you provide me with a few lines of (pseudo) code?

BR,

Carsten Voort

Please Log in or Create an account to join the conversation.

More
22 Dec 2016 11:54 #4691 by support
Replied by support on topic Opc Ua ExtensionObject
I should add one more things: If you only have one, or a handful of data types you need to deal with, and you need them upfront (i.e. you are connecting to an OPC server/configuration that you know), the recommended steps can be made much easier (and you wouldn't even need the extra assemblies).

Let's say you are dealing with one custom data type, which is represented by 10 bytes inside the ExtensionObject. As part of you development (i.e. not directly in the program you are writing), you can read the DataType and determine the DataTypeDescription using my hints - but just once, manually. You will end up with an XML fragment that describes the fields of the custom data type. You will then write a custom decoding algorithm (into the actual project you are developing) that would take these 10 bytes and interpret them accordingly to the data type description - that should be just couple of lines of code. If you have just one data type or a handful of them, this approach is *much* simpler than trying to write a generic solution, which is what I assumed in my hints.

Best regards

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.065 seconds