How to model array of structures?

1,736 views
Skip to first unread message

Grant Edwards

unread,
Dec 7, 2016, 3:29:20 PM12/7/16
to open62541
I've been reading through the example server code, the API documentation and the OPC/UA spec.  But, I still haven't figured out how one represents the equivalent of what in C would be an array of struct.    Let's say I've got a structure called a "port" that has a a couple dozen fields of different types (a field might be an array of bytes, a string, a float, an int or another struct).

Now I want to model a device that has 4, 8, or 16 of those "port" structures.

All the examples I find of arrays in OPC/UA are arrays of simple scalar types (array of byte, array of int, array of string).

Am I supposed to define a "port" object type and then just define four different instances named port1 port2 port3 port4?

Or can I create an array of objects?



Julius Pfrommer

unread,
Dec 7, 2016, 6:25:53 PM12/7/16
to open62541
Hello Grant,

there are several ways to achieve this.

- Create a custom data type for the "struct". You can then also make arrays with the "struct".
We currently generate struct definitions from the standard xml format. Please have a look at the "types" section of the documentation and compare with /tools/schema/Ua.Types.bsd.
This however requires that both client and server have the definition compiled in. We don't offer the creation / introspection of structs at runtime currently.
- Create an object (type) that contains several member variables of "builtin" type. You cannot make an array of objects. But you can nest objects with member objects.

Best regards,
Julius

Grant Edwards

unread,
Dec 8, 2016, 10:23:19 AM12/8/16
to open62541


On Wednesday, December 7, 2016 at 5:25:53 PM UTC-6, Julius Pfrommer wrote:
Am Mittwoch, 7. Dezember 2016 21:29:20 UTC+1 schrieb Grant Edwards:
 
I've been reading through the example server code, the API documentation and the OPC/UA spec.  But, I still haven't figured out how one represents the equivalent of what in C would be an array of struct.    Let's say I've got a structure called a "port" that has a a couple dozen fields of different types (a field might be an array of bytes, a string, a float, an int or another struct).

there are several ways to achieve this.

- Create a custom data type for the "struct". You can then also make arrays with the "struct".
We currently generate struct definitions from the standard xml format. Please have a look at the "types" section of the documentation and compare with /tools/schema/Ua.Types.bsd.
This however requires that both client and server have the definition compiled in. We don't offer the creation / introspection of structs at runtime currently.

[Thanks for the quick answer (and your work on the stack!).]

That's what I was afraid of.  Is this what is referred to as "structured Data Type and a simple Variable" in OPC/UA spec Part-3 §A.4.3b?  If the structure of the data and the individual values don't show up in the address space when using a UA browser, then I don't see how this approach would be acceptable to our customers.
 
- Create an object (type) that contains several member variables of "builtin" type. You cannot make an array of objects.

That's what I had understood from reading the specification, but I couldn't believe it.  I was sure I must be misunderstanding the spec.  Expecting that a real-world automated system will never have multiple instances of any subsystem just didn't sound realistic.  That would be like designing an OS that can only support a single network interface, a single printer, a single serial port, etc.
 
But you can nest objects with member objects.

Can you create multiple instances of an object?

Do you have to seperately create each instance of each object's nested/contained variable seperately?  If you have mutliple instances of an object, how do the data source functions for the contained/nested vaiables know which parent object instance they belong to?

I seem to be missing some fundamental concept of OPC/UA, because from reading the spec and looking at examples, I can't see how the address space and data modelling can handle common real-world devices that contain multiple instances of a subsystem.

Julius Pfrommer

unread,
Dec 9, 2016, 1:32:55 AM12/9/16
to open62541
Hello there,


That's what I was afraid of.  Is this what is referred to as "structured Data Type and a simple Variable" in OPC/UA spec Part-3 §A.4.3b?  If the structure of the data and the individual values don't show up in the address space when using a UA browser, then I don't see how this approach would be acceptable to our customers.

It will show up if both sides have agreed on the DataType (that is treated like a scalar "blob"). Many Companion Specifications define custom structured data types.
For example "position" (x,y,z + rotation). Note that the "data" is the value attribute of a variable node. The node has more attributes (name, access rights, ..) and references to other nodes in the information model graph. In the information model graph, you can nest variables (similar to objects). Only when the variable is defined as a property of an object is it forbidden to have "child" nodes.

Note that OPC UA is designed for machine to machine interaction. You don't necessarily have a human "browsing".
 
- Create an object (type) that contains several member variables of "builtin" type. You cannot make an array of objects.

That's what I had understood from reading the specification, but I couldn't believe it.  I was sure I must be misunderstanding the spec.  Expecting that a real-world automated system will never have multiple instances of any subsystem just didn't sound realistic.  That would be like designing an OS that can only support a single network interface, a single printer, a single serial port, etc.
 
But you can nest objects with member objects.

Can you create multiple instances of an object?

Do you have to seperately create each instance of each object's nested/contained variable seperately?  If you have mutliple instances of an object, how do the data source functions for the contained/nested vaiables know which parent object instance they belong to?

I seem to be missing some fundamental concept of OPC/UA, because from reading the spec and looking at examples, I can't see how the address space and data modelling can handle common real-world devices that contain multiple instances of a subsystem.

You can make multiple instances of object types. Object types are similar to classes in regular programming languages.

Plese refer to our documentation. It is still quite developer-centric but should serve well as an addition to reading the spec.
http://open62541.org/doc/current/tutorial_noderelations.html
http://open62541.org/doc/current/information_modelling.html
http://open62541.org/doc/current/types.html

For learning, it always a good idea to take a generic client with a GUI (such as UAExpert) and connect to an example server.
Especially take a look at how references are used to structured the information model.

Best regards,
Julius

Julius Pfrommer

unread,
Dec 9, 2016, 1:38:17 AM12/9/16
to open62541
I forgot something.
If your custom data type is not known to either side (client or server).
You can still send it, store it, etc.
It will be automatically wrapped with additional information on the encoding and the encoding length.
So it will be treated as an opaque blob. And yes, you can have arrays of such blobs as the value of a variable node.
Reply all
Reply to author
Forward
0 new messages