OPCFoundation / UA-.NET-Legacy

OPC Foundation Unified Architecture .NET Reference Implementations
330 stars 297 forks source link

How to define and use custom structure type? #85

Open astrowalker opened 7 years ago

astrowalker commented 7 years ago

Say I would like to define type Person with "fields" Name and Age in terms of OPC-UA. Also I would like to define variable node person of type Person and write to that node in one step. How to do it?

Please note: when I update person with such data (Kevin, 47), (Jane, 22) client should get in subscription, or when reading the variable directly only those 2 pairs, not something like (Kevin,22).

randy-armstrong commented 7 years ago

From a specification perspective you would:

Create a DataType (PersonDataType). It is a subtype of Structure. Use that DataType as the DataType for a Variable. When reading the Value attribute you would get an ExtensionObject (a.k.a. Structure). The ExtensionObject would contain a serialized version of PersonDataType. For writing you would create an ExtensionObject with a PersonDataType and write to the Value attribute.

The UA Sample Library project has numerous examples of the above in TestData folder.

astrowalker commented 7 years ago

@SparhawkSoftware , thank you!

For clarification, "Create a DataType (PersonDataType)" -- as a node in ObjectTypes, correct?

"The UA Sample Library project has numerous examples of the above in TestData folder." Do you know any straightforward example? Because all I found is "TestData.DataTypes" file which creates randomly single field structure (at least this is my understanding) -- still reading this one example. I didn't find any other.

Update: I found DataType creator in workshop files (ReferenceNodeManager), so I created a type, yet without any fields. I.e. I create fields but they are not visibile (for example in UA Expert). Maybe it is related to fact I create my type with Objects folder (because so far I am unable to create subfolder inside Types/DataTypes).

benjamin1988 commented 6 years ago

Is their any possibility to rebuild the custom server data types at client side? Now i have to rebuild all custom types in the client application, it would be nice to have a generic function to create a data type with the definition of an encodable ExtensionObject. Or even with a TypeDefinition of a Object Type.

ZbynekZ commented 6 years ago

For clients written in .NET, QuickOPC has support for custom types (OPC UA "Complex data"). It can decode and encode the extension objects for you, automatically. See QuickOPC 2018.1 release announcement and OPC UA Complex Data Extensions documentation.