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 complex data types
May 23, 2023
19:16, EEST
Avatar
dulbricht
New Member
Members
Forum Posts: 2
Member Since:
May 23, 2023
sp_UserOfflineSmall Offline

Hi,

how does the SDK handle complex data types, that is attributes where the value is a structure? In the docs it says there is a code generator that generates java code from an XML description. That is kind of impractical as it means re-building and re-deploying the application whenever any data model changes or a new data model needs to be supported. Is it possible to read and write complex data types without generated code? Also, is there a way to try this with the free simulation server? I added some attributes to a node in the simulation server but when I read them with the console sample the SDK always had a special (generated?) serializer for the data types.

May 24, 2023
8:35, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

This is a complex topic. I do skip some details in this answer.

I do assume here you mean about the current SDK 4.x and not something historical. Though, I must say that some of the documentation is lacking and a bit outdated.

SDK 1.x didn’t support custom complex types. 2.x supported (only) via Codegen, in 3.x we added dynamic ways that do not need Codegen and now in 4.x basically the intention (and most of the reality and common use-cases) is that Codegen is just basically syntactic sugar and optional. You can see this in action if you use https://www.prosysopc.com/products/opc-ua-browser/ (that is made using 4.x), it should be able to visualize most Structures in the Attributes view. Assuming it can visualize it, any Client made with the SDK should as well. If not, let us know.

The core OPC UA namespace “http://opcfoundation.org/UA/” is special and already generated by us within the SDK as it internally heavily relies on it. Or technically it is generated from a special NodeSet that contains both the core namespace and “OPC UA service descriptors” (that are also work the same way as Structures).

There are 2 parts to custom Structures: one is that the SDK must be able to encode/decode them and second is that you as a user must have API to use them.

By default UaClient during connect will read/browse the Types part of the server, one of the reasons is that it fetches the metadata of custom structures (skipping other reasons here). There are nowadays multiple ways in OPC UA to represent them. Historically there were so called “DataTypeDictionaries”, but the modern way is via (1.04 added this) DataTypeDefinition. If SDK cannot resolve everything via DataTypeDefinition it will look the dictionaries (but they cannot represent new 1.04 features such as multidimensional fields).

Thus, if you Read a node that had a Structure Value, you should receive DataValue->Variant->Structure instance. If not and you received an ExtensionObject instead, it means SDK wasn’t able to decode it (or that you have set the UaClient not to read the types).

If you have a com.prosysopc.ua.stack.builtintypes.Structure at hand, you can call .specification() on it to get a StructureSpecification and then .getFields() to get the Structure fields, then you can interact on the Structure with generic set/get taking in the fields (FieldSpecification or the name).

If you do not have the structure at hand and just wish to write one, assuming you have connected to the server, you should be able to find the StructureSpecification via (UaClient) client.getEncoderContext().getStructureSpecification(UaNodeId). Then you can call toStructureBuilder and built the Structure via the Structure.Builder. If you wonder why there is a Builder, I hope some distant day in the future we can make Structures immutable and preferably where possible they should be treated as such now if given to SDK (e.g. as a node value), even though they technically are not for historical reasons.

It is not possible to simulate this with the free version of Simulation Server, but technically speaking you kinda cannot even with the Pro version (you can temporarily set a value, but we cannot persist structure values yet, will be added at some point in the future). However, the SDK samples sampleconsoleserver does have 2 custom Structure types defined in code, see com.prosysopc.ua.samples.server.MyNodeManager.createCustomStructure() and com.prosysopc.ua.samples.server.MyNodeManager.createCustomStructureWithCustomStructureField(). That also shows a bit of using the StructureSpecification and making the instances of those structures.

Since this is quite long now I’ll stop here, but let us know if you have more questions or some part of the above was unclear.

June 14, 2023
14:25, EEST
Avatar
dulbricht
New Member
Members
Forum Posts: 2
Member Since:
May 23, 2023
sp_UserOfflineSmall Offline

Thanks for the explanation, this clears up the topic for me.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
17 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 77

Ibrahim: 76

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

fred: 41

Member Stats:

Guest Posters: 0

Members: 681

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6261

Newest Members:

graciela2073, sagarchau, elviralangwell4, Donnavek, Eddiefauth, DonaldPooma, fidelduke938316, Jan-Pfizer, DavidROunc, fen.pang@woodside.com

Moderators: Jouni Aro: 1010, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 983, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 321, Lusetti: 0, Ari-Pekka Soikkeli: 5

Administrators: admin: 1