Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Handling an Array of DataStructures with subtypes
July 11, 2024
16:34, EEST
Avatar
hbrackel
Member
Members
Forum Posts: 144
Member Since:
February 21, 2014
sp_UserOfflineSmall Offline

Good afternoon.

I have created a custom structure DataType with 2 subtypes, for instance:
MyStructredBaseDataType
– MyStructuredSubDataTypeA
– MyStructuredSubDataTypeB

and want to expose a single array containing a mixture of MyStructuredSubDataTypeA and MyStructuredSubDataTypeB on a (Prosys based) OPC UA Server. I tried to generate code from this setup but the code did not reflect my intention. I also tried this with the baseDataType being abstract or non-abstract..

My question now is whether this can work at all conceptually, because a client attempting to read the array would certainly also need the related encodings. If the array has been typed with the BaseStructuredDataType (as a super type), does a client have any chance of decoding array elements having the subTypes? Something which does work is creating 2 arrays, one each per subtype. But then the original ordering of the mixed typed array would need to be reconstructed by introducing a dedicated index field (NB: The wording of the mixed array elements is critical to the application).

Thank you very much

July 12, 2024
11:42, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1017
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

It is a bit unclear do you mean directly in a node Value (i.e. you give the ‘structure-array’ directly to Variant) or do you have a Structure that has the structure-array as a field. Since you do mention “2 arrays” and “index field”, maybe the latter, but that too was more about “work at all conceptually” so I’m not sure. Though, both ways should work, but the latter one needs probably more explanations.

In the case of having the structure-array directly in a node (i.e. you use it to make the Value Variant). Structures within Variant are encoded (in the binary transit) as ExtensionObjects (builtintype 22). An array of Structures becomes an array of ExtensionObjects, basically each element has their own type info (as part of the ExtensionObject encoding). This also has the side-effect that on the “encodings-level” an empty array of structures doesn’t have a type (SDK patches this info in some cases once we are in the “node datatype level”). Also, the decoder will choose the most-subtyped version of the array that can fit the elements. Thus if they are all MyStructuredSubDataTypeB then it is MyStructuredSubDataTypeB[] (which might cause issues if you then try to assign MyStructuredSubDataTypeA). Could be some room for improvements..

In the case of having the structure-array as a field in a structure, it should work, but you must either have a “normal structure” and i=22 (the raw ‘Structure’ DataType) as the field type OR have a “StructureWithSubtypedValues structure” and mark the field as AllowSubTypes true and then have the base MyStructredBaseDataType as the field DataType. However! Note that Codegen will create an ExtensionObject[] field in both cases. This is because currently generated structure types in the SDK cannot represent their subtypes and it is possible a non-generated model extends a generated Structure thus it would be impossible java-wise to set ‘DynamicStructure’ representing the non-generated subtype as an element of a generated structure type array (ExtensionObject is the only thing that can handle both). Thus you will need to handle this data as ExtensionObject[] and take the structures by ExtensionObject.getObject() (they should be decoded as long as the client knows the types either by codegen or has read them during connect).

July 13, 2024
14:13, EEST
Avatar
hbrackel
Member
Members
Forum Posts: 144
Member Since:
February 21, 2014
sp_UserOfflineSmall Offline

I am sorry for being a little in-precise in my description..

MyBaseStructureDataType
– Element: UInt32 Index
– more elements
– SubType MyStructuredSubDataTypeA
– SubType MyStructuredSubDataTypeB

CustomParentDataStructure
– Element: UInt32 Index
– more Elements
– Element: MyBaseStructureDataType[] Params ## populated with ExtensionObjects values of the subtypes of MyBaseStructureDataType

(Server) Variable: CustomVariable, DataType: CustomParentDataStructure

I changed the array to type MyBaseStructureDataType with subtypes allowed, as you suggested, and put the individual array elements of the encoded sub-typed structures as ExtensionObjects into the array. (basically an ExtensionObject[] matching the generated code)

UaExpert can now successfully decode the individual array elements successfully, while the Prosys OPC UA Browser (v5.0.0-173) shows the array elements as ExtensionObjects. I assume the latter is to be expected if I interpret your description above correctly.

Originally, I marked the “MyBaseStructureDataType” as abstract, because there can only be instances of its subtypes. UaModeler then does not generate encodings for the abstract data structure type, which I think is correct, but some clients developed with other SDKs can’t work without those encodings. So I had to make the “MyBaseStructureDataType” non-abstract again.

Thank you very much for your support – as always 🙂

July 15, 2024
12:09, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1017
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hmm.. seems UaExpert is better in this regard, I’ll mark this as an improvement idea for Browser. Like technically the data is visible in the tooltip (or if you copy it to clipboard), though this is mostly a side-effect (of ExtensionObject.toString), anyway not very usable… but we should probably show it the same way (or make it expandable at least).

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
15 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Heikki Tahvanainen: 402

hbrackel: 144

rocket science: 86

pramanj: 86

Francesco Zambon: 83

Ibrahim: 78

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

Member Stats:

Guest Posters: 0

Members: 737

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1510

Posts: 6399

Newest Members:

helenmcrae1419, srijithvijay, tammyhillier, rodsFioravanti, Sairamreddy, wj, valentinafluhart, accusneds, Jamesses, DavidLarry

Moderators: Jouni Aro: 1019, Pyry: 1, Petri: 0, Bjarne Boström: 1017, Jimmy Ni: 26, Matti Siponen: 340, Lusetti: 0

Administrators: admin: 1