Structure with subtyping and Optional fields|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
Structure with subtyping and Optional fields
Avatar
Rahul Rahul_1
Member
Members
Forum Posts: 5
Member Since:
11/06/2023
sp_UserOfflineSmall Offline
1
02/23/2024 - 04:57
sp_Permalink sp_Print

Hi

According to UA1.05, Can a StructureWithSubtypedValues Structure Type have optional field?

If Not than what if - 

Question 1: If the parent is a "StructureWithOptionalField" and the child has a field with "AllowSubtypes" set to true, then the child should treat the parent's optional field as mandatory. Alternatively, the child should ignore "AllowSubtypes" for its own field. And same situation if parent is "StructureWithSubtypedValue" and child has optional field.

Question 2: For a perticular field in a structure if both "Allowsubtypes" as well as "IsOptional" specified as true what should we consider at first place.

 

Thanks

Rahul

Avatar
Randy Armstrong
Admin
Forum Posts: 1451
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
02/23/2024 - 05:41
sp_Permalink sp_Print sp_EditHistory

Q1) OptionalField and AllowSubtypes are mutually exclusive. i.e. if StructureWithOptionalField is set then no fields can have AllowSubtypes.

See https://reference.opcfoundatio...../docs/8.51

If the structureType is StructureWithOptionalFields this field indicates if a data type field in a Structure is optional. In this case a value of FALSE means the StructureField is always present in all occurances of the Structure DataType and a value of TRUE means the StructureField may be present in an occurance of the Structure DataType.

If the structureType is Structure or Union this field shall be FALSE and shall be ignored.

If the structureType is StructureWithSubtypedValues, or UnionWithSubTypedValues this field is used to indicate if the data type field allows subtyping. Subtyping is allowed when set to TRUE.

Q2) See Q1

If a modeller needs to use optional fields and AllowSubtypes then it should create nested structures.

Avatar
Mohit Agarwal
Member
Members
Forum Posts: 51
Member Since:
10/18/2019
sp_UserOfflineSmall Offline
3
02/26/2024 - 03:54
sp_Permalink sp_Print

Hi Rahul, Randy,

Adding a special case too.

A structure can have a BaseDataType field for which AllowSubTypes = FALSE. But as the Data Type is abstract, it implicitly means, sub-types are allowed.

Example: https://reference.opcfoundatio...../docs/10.5

This is JUST information and clarify on additional use case interpretation.

Avatar
Randy Armstrong
Admin
Forum Posts: 1451
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
4
02/26/2024 - 04:59
sp_Permalink sp_Print

Same rule applies to Structure. The apparent inconsistency was added to ensure existing NodeSets would still be valid when we introduced the AllowSubtypes flag.

Avatar
Rod Stein
New Member
Members
Forum Posts: 1
Member Since:
08/18/2014
sp_UserOfflineSmall Offline
5
03/05/2024 - 08:37
sp_Permalink sp_Print

Randy, are you saying that the following is not allowed because A would be a StructureWithOptionalType = True.

Structure Type A has three fields, A1, A2, and A3 (A3 is optional).

Structure Type B is derived from A and Adds a B1 field (this part is what you say is not allowed).

So you get:

MyAInstance - A1, A2, A3(o)

MyBInstance - A1, A2, A3(o), B1

 

What you are saying is because A has an optional filed you would need to do this:

A is the same

B is a new type with a field of B1 and a field of A (nested structure).  No subtyping, just structure nesting giving you:

MyAInstance - A1, A2, A3(o)

MyBInstance - B1, MyAInstance

Avatar
Randy Armstrong
Admin
Forum Posts: 1451
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
6
03/05/2024 - 22:46
sp_Permalink sp_Print

The AllowSubtypes flag restricts the field - not the containing type.

So a type { A1, A2, A3(o) } could have subtype { A1, A2, A3(o), B1 } provided the DataType of B1 is concrete.

But it could not have a field B1 where instances of C1 or any subtype of C1 are allowed

If you needed a field B1 with an abstract DataType C1 then you could use Structure or BaseDataType instead of C1.

If you really wanted to preserve the C1 DataType then you could use the aggregation scheme you proposed:

{ A: Type A, B1: Type C1 }

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