Query on Structure Sub-types in UA 1.04 and UA 1.05.02|OPC UA Standard|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
Query on Structure Sub-types in UA 1.04 and UA 1.05.02
Avatar
Mohit Agarwal
Member
Members
Forum Posts: 51
Member Since:
10/18/2019
sp_UserOfflineSmall Offline
1
07/27/2023 - 00:06
sp_Permalink sp_Print

Hi,

This query has a relation to another post: https://opcfoundation.org/foru.....pes/#p4786

In UA 1.05.02, we introduced, AllowSubTypes option, but based on the above post, the answer was, it is NOT a change over the wire but ONLY for code generation.

Question: In UA 1.04, if we have a complex structure, then is it allowed to send the content of a sub-type for a given instance of complex structure?

Example: ResultDataType { ResultMetaDataType resultMetaData; }

ResultMetaDataType extended as ResultMetaExtendedDataType. Now, in the instance of ResultDataType, can I pass an instance of ResultMetaExtendedDataType to resultMetaData field as per UA 1.04?

Avatar
Randy Armstrong
Admin
Forum Posts: 1457
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
07/27/2023 - 00:30
sp_Permalink sp_Print sp_EditHistory

In 1.04 AllowSubtypes was implemented by setting the DataType to Structure when subtypes are allowed (i.e. the DataTypeDefinition loses information and descriptive text is used to explain what is actually allowed).

In 1.04 if the DataType is not Structure then only instances of that type are allowed.

If a Server wants to publish a DataTypeDefinition using AllowSubtypes that a 1.04 client can understand then it needs replace the supertype with Structure when it creates the DataTypeDefinition that is returned in a Read.

Avatar
Mohit Agarwal
Member
Members
Forum Posts: 51
Member Since:
10/18/2019
sp_UserOfflineSmall Offline
3
07/27/2023 - 08:39
sp_Permalink sp_Print

Thanks a lot Randy, that makes it clear for me. I have tried changing the concrete type to Structure and initial test worked, I am checking if that works for required scenarios for me and update the details if I have any other findings.

Avatar
Mohit Agarwal
Member
Members
Forum Posts: 51
Member Since:
10/18/2019
sp_UserOfflineSmall Offline
4
07/29/2023 - 20:41
sp_Permalink sp_Print

I have a linked question and wanted to confirm my understanding for the same. In the following structure, can you please suggest you inputs on it?

ResultDataType

ResultMetaDataType resultMetaData;

Array<BaseDataType> resultContent;

}

We should be able to populate resultContent with instances of ResultDataType (the parent Result) also as it is an array of BaseDataType. I hope it is correct to do that since we have a use case of several parent and child results. 

Or if my assumption is wrong, are there any restrictions which needs to be handled apart from application logic?

Avatar
Randy Armstrong
Admin
Forum Posts: 1457
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
5
07/30/2023 - 11:47
sp_Permalink sp_Print

It is not clear what language you are using.

In C# you need an ExtensionObject[] which represents an array of Structures.

And array of Variant[] (a.k.a. BaseDataType) is something different.

Avatar
Mohit Agarwal
Member
Members
Forum Posts: 51
Member Since:
10/18/2019
sp_UserOfflineSmall Offline
6
07/30/2023 - 11:55
sp_Permalink sp_Print sp_EditHistory

I am using C++ based SDK and it is more like Array of Variant (BaseDataType).

Hence, my assumption is, we can have parent-child relationship since in the end ResultContent is an array of BaseDataType.

ResultDataType.ResultContent[] should be able to point to an element of type ResultDataType?

Technically, Structure (ExtensionObject) is a sub-type of BaseDataType, hence logically, I assume that BaseDataType[] ResultContent[] can still hold ResultDataType.

Additional Information:
When I passed, ResultDataType.ResultContent[] = Some other Structure, it WORKED but when I passed ResultDataType.ResultContent[] = elements of ResultDataType, then I was facing some issues which I am still troubleshooting.

But wanted to understand, if there are any restrictions on this use case in UA 1.04 which are resolved in later version of UA?

Avatar
Randy Armstrong
Admin
Forum Posts: 1457
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
7
07/31/2023 - 05:57
sp_Permalink sp_Print sp_EditHistory

Technically, Structure (ExtensionObject) is a sub-type of BaseDataType, hence logically, I assume that BaseDataType[] ResultContent[] can still hold ResultDataType.

The binary encoding of a ExtensionObject[] is different from the binary encoding of Variant[]. If you want to replicate the effect of the AllowSubtypes flag with tools that do not understand it then you need to use ExtensionObject[] as the field DataType.

I passed ResultDataType.ResultContent[] = elements of ResultDataType, then I was facing some issues which I am still troubleshooting.

You need to create an ExtensionObject[] which wraps an instance of ResultDataType in each element. If you use a SDK with a BaseDataType in the API you could be accidently creating a 1 element Variant[] which contains a ExtensionObject[] instead of an ExtensionObject[].

Avatar
Mohit Agarwal
Member
Members
Forum Posts: 51
Member Since:
10/18/2019
sp_UserOfflineSmall Offline
8
07/31/2023 - 06:09
sp_Permalink sp_Print sp_EditHistory

Yes, the current C++ SDK does NOT understand AllowSubTypes and is based on UA 1.04. Hence, is the following change correct?

Ok, in that case, if I understand you correctly, the following is the recommendation.

Current Schema:

ResultDataType

ResultMetaDataType resultMetaData;

Array<BaseDataType> resultContent;

}

Updated Schema:

ResultDataType

ResultMetaDataType resultMetaData;

Array<Structure> resultContent; //Updated from BaseDataType to Structure so that it is PARSED as ExtensionObject. I should now be able to pass element of ResultDataType in resultContent?

}

Second Question: I guess, parent-child structures can exists. I want to cofirm this since all our information model from the CS is based on Parent-Child, where resultContent will point to an element of parent type only?

Third Question: When, it was Array<BaseDataType> resultContent, I passed some other Array of Structure and that worked. In that case, it means, Array of Variants was pointing to Array of Extension Objects. But, the same did NOT work when I passed parent type. Not Sure of the reason as of now and still troubleshooting it.

Avatar
Randy Armstrong
Admin
Forum Posts: 1457
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
9
07/31/2023 - 13:08
sp_Permalink sp_Print

Array<Structure> resultContent; //Updated from BaseDataType to Structure so that it is PARSED as ExtensionObject. I should now be able to pass element of ResultDataType in resultContent?

This should work if the C++ SDK serializes as an Array of ExtenionObjects. See https://reference.opcfoundatio.....s/5.2.2.15

Second Question: I guess, parent-child structures can exists. I want to cofirm this since all our information model from the CS is based on Parent-Child, where resultContent will point to an element of parent type only?

An ExtensionObject is a wrapper that includes the DataTypeEncodingId and the actual Object. The DataTypeEncodingId allows you to know what the Object is so you can cast it to the correct type. If the DataTypeEncodingId is a subtype of ResultDataType then you can cast it to the subtype or ResultDataType depending on what you need.

Third Question: When, it was Array<BaseDataType> resultContent, I passed some other Array of Structure and that worked. In that case, it means, Array of Variants was pointing to Array of Extension Objects. But, the same did NOT work when I passed parent type. Not Sure of the reason as of now and still troubleshooting it.

A Variant can contain Arrays so care must be taken to ensure you do not set the value of a single Variant to an Array when you intended to have an array of Variants with each element containing a scalar value.

Avatar
Mohit Agarwal
Member
Members
Forum Posts: 51
Member Since:
10/18/2019
sp_UserOfflineSmall Offline
10
08/01/2023 - 04:03
sp_Permalink sp_Print sp_EditHistory

Thanks a lot Randy, please find the updates on the troubleshooting and can you please suggest your inputs for following case?

  • I have tried parent-child recursion and it works with both BaseDataType[] array and Structure[] array as long as I ensure that Variant[] array is mapped to ExtensionObject[] array instead of scalar ExtensionObject/scalar Variant.
  • Last Pending Thing:
    • ResultDataType //Contains 2 fields shown below:
      • ResultMetaDataType resultMetaData //Contains 1 Mandatory field and 19 optional fields.
      • Array<BaseDataType> resultContent;
  • NEXT STEP: Extension of ResultMetaDataType Field
  • JoiningResultMetaDataType : inherits ResultMetaDataType //It contains additional 11 optional fields.
  • In total ResultMetaDataType (Parent Type) contains 20 fields and JoiningResultMetaDataType (Sub-type) contains 11 additional fields.
  • Now, when I created instances of JoiningResultMetaDataType, the DataTypeDefinition ONLY points to 11 fields and does NOT show 20 fields of the ResultMetaDataType (Parent Type).
  • The only workaround what I can see right now is to to DUPLICATE all the properties defined in ResultMetaDataType (20 fields) inside JoiningResultMetaDataType (which will be 20 + 11 fields = 31 fields).
  • Questions:
    • Is it due to lack of support of UA 1.05.02 by both Server and Client?
    • In UA 1.04, Is it NOT possible to have sub-types where it can include all the parent-type properties? 
    • Will marking ResultMetaDataType (Parent Type) to Structure work?
      • I tried this but it was giving some other issue and can check again.
Avatar
Randy Armstrong
Admin
Forum Posts: 1457
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
11
08/01/2023 - 22:08
sp_Permalink sp_Print sp_EditHistory

I don't really understand what the SDK you are using is doing.

There are no optional fields in these structures so your comments about optional fields make no sense.

Subtypes always inherit parent properties but ANSI C code generators have to copy properties because there are no supertypes in ANSI C.

Avatar
Mohit Agarwal
Member
Members
Forum Posts: 51
Member Since:
10/18/2019
sp_UserOfflineSmall Offline
12
08/01/2023 - 22:58
sp_Permalink sp_Print

It is C++ based SDK.

ResultMetaDataType (First field in ResultDataType) has 19 OPTIONAL fields and 1 Mandatory Field

I am creating JoiningResultMetaDataType (with additional 11 OPTIONAL fields) which inherits ResultMetaDataType. Basically it is a structure with StructureType = 1 (StructureWithOptionalFields)

If parent type has all mandatory fields, then SDK creates it correctly where it copies all the parent type fields in the DataTypeDefinition

Hence, my question was, in UA 1.04, is there any different way to handle Sub-Types of StructureWithOptionalFields?

Basically, before the code-generation, the DataTypeDefinition of the sub-type does NOT include the parent properties.

[Image Can Not Be Found]

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 22
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1353
Posts: 4589