19:56, EEST
June 27, 2012
Is it possible to create nested complex types with arrays?
For example, I would like to be able to define a type Name, which would contain two strings- First Name and Last Name.
Then I would like to be able to define a type that contains an array of names and also an integer or some other member.
Name:
FirstName (String)
LastName (String)
OuterType:
Id (Integer)
People (Array of 5 Name objects)
7:21, EEST
December 21, 2011
Hi Tim,
If I understand you correctly, you want to define a DataType Name, which consists of two strings (FirstName and LastName). Then you want to define OuterType (either an ObjectType or VariableType) that has two components, Id and People. Once you’ve defined a custom DataType Name, you can simply create an array of them in a Node. So People would have as its value an array of Names.
However, using a custom DataType has the drawback of most UA clients not being able to understand it. Another option is to simply create FirstName and LastName as two Properties for Name. You can see an example in any UA server address space in ServerStatus node (Root -> Objects -> Server – ServerStatus), where the same information is available as a single value of ServerStatus and as Property nodes of it. While all UA clients can understand ServerStatusDataType, if they didn’t, they’d be able to access the same information in the Property nodes (CurrentTime, State, etc.) The exact same goes for the Property BuildInfo, and actually ServerStatusDataType contains also BuildInfo! So you have some choice on how to do this.
I hope this clarified DataTypes and Properties as two choices in exposing this information. Depending on your application and the expected clients the best practice may vary.
13:35, EEST
June 27, 2012
Ideally I would like clients who understand the complex types to be able to read OuterType or Name nodes as a single value, and clients who don’t to be able to read the pieces as properties. I think I understand how to do this if there aren’t any arrays involved:
OuterObject (OuterType)
HasComponent Id(Integer)
HasComponent Person
Person (NameType)
HasComponent FirstName(String)
HasComponent LastName(String)
If I want OuterObject to contain an array of names called people, I’m not clear on how that would work. I can create a node People of NameType that is a component of OuterObject, and give it array dimensions, but then how can I give each element of the array a FirstName and LastName property?
11:20, EEST
December 21, 2011
Yes, that is what could be considered as best practice since it allows quick and efficient access (via the custom DataType) as well as interoperability (via the Properties which all clients can understand). I wrote a blog post about using custom DataTypes, check it out if you haven’t already: http://www.prosysopc.com/blog/…..datatypes/
There are a few ways to model this:
1) OuterObject has HasComponent references to several Person nodes (so there is no single People node) and each of these Person nodes has as its DataType NameDataType (distinct from NameType, which is a VariableType with the two properties) and has the two Properties with DataType String. All the Person nodes have the same BrowseName, so TranslateBrowsePathsToNodeIds service calls involving these nodes will return all of them.
2) Have the DataType of People to be NameDataType and for People to contain an array of NameDataType. So once you have defined NameDataType, just create an array of those and place it as the value. FirstName and LastName then contains arrays of strings.
The spec is not completely clear about what the best practice in this kind of use case (with arrays) is. I would recommend approach 1), even though it involves more nodes.
19:33, EET
June 27, 2012
The example above is exactly what I needed. Now I can expose my custom types, and the client can read them if it knows their format in advance.
Now I would like to set up the information a client would need to discover the format.
It looks like I need to add things in a few places for this to work. For example, I need to add a new type under Structure:
Types
DataTypes
BaseDataType
Structure
(MyDataType)
MyDataType needs to have a HasEncoding reference to a description of the type.
Do you have an example of setting something like this up? Also, do you know of any clients that can read the encoding description nodes and take custom types apart using them?
14:00, EET
December 21, 2011
Most Users Ever Online: 1919
Currently Online:
21 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 88
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 738
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1529
Posts: 6471
Newest Members:
mickey21654, donnyredmond08, keesha4235, cheribruce, candacekolb4, Garmcrypto7Zof, calebhardison, susannahdingle7, inilarythikibia, rickykennionModerators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0
Administrators: admin: 1