Can Enumeration values return bitwise OR of multiple field identifiers?|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
Can Enumeration values return bitwise OR of multiple field identifiers?
Avatar
EG
Member
Members
Forum Posts: 35
Member Since:
12/06/2021
sp_UserOfflineSmall Offline
1
06/06/2022 - 07:05
sp_Permalink sp_Print

Hi

If I have a type defined that derives from Enumeration, with fields defined such that the identifiers are powers of two, can a value be returned which is bitwise OR of multiple fields?

For example, MyEnumerationType which derives from Enumeration

FieldA = 1, FieldB = 2, FieldC = 4

Then a Variable with DataType=MyEnumerationType and the value = 3, indicating to the client that both FieldA and FieldB are applicable

Thanks

Avatar
Randy Armstrong
Admin
Forum Posts: 1564
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
06/06/2022 - 08:19
sp_Permalink sp_Print

You need to use an OptionSet - not an Enumeration.

https://reference.opcfoundatio.....rt3/5.8.3/

The OptionSetValues Property shall provide an array of LocalizedText containing the human-readable representation for each bit.

Avatar
EG
Member
Members
Forum Posts: 35
Member Since:
12/06/2021
sp_UserOfflineSmall Offline
3
06/07/2022 - 02:01
sp_Permalink sp_Print

Thanks Randy

This is unfortunate, because it appears OptionSet is not supported by the model compiler. I see you made this commit in 2018: https://github.com/OPCFoundati.....a01d365824 so I wondered if I am doing anything wrong.

Should the base type for a defined OptionSet be OptionSet? When I define the type:

<DataType SymbolicName="MD:MyEnumerationType" BaseType="OpcUa:OptionSet" IsOptionSet="true">
<Fields>
<Field Name="FieldA" Identifier="1"/>
<Field Name="FieldB" Identifier="2"/>
<Field Name="FieldC" Identifier="4"/>
</Fields>
</DataType>

The model compiler tries to produce a C# enum that is derived from Opc.Ua.OptionSet, which of course then fails to compile (because Opc.Ua.OptionSet is a class).

Additionally, any class that tries to use create a variable of this OptionSet generates invalid IEncoder functions, as it tries to call the non-existent function IEncoder.WriteUserDefined in order to encode the option set.

Avatar
EG
Member
Members
Forum Posts: 35
Member Since:
12/06/2021
sp_UserOfflineSmall Offline
4
06/07/2022 - 02:16
sp_Permalink sp_Print

I see that UA Defined Types.xml defines OptionSets with integer base types, which fixes the compilation issue, but I am confused how this then relates to OPC 10000-3 8.41 which says OptionSet is a structure with two ByteString fields.

Avatar
Randy Armstrong
Admin
Forum Posts: 1564
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
5
06/07/2022 - 08:51
sp_Permalink sp_Print

<!-- UpdateBehavior -->
<DataType SymbolicName="DI:UpdateBehavior" BaseType="OpcUa:UInt32" IsOptionSet="true">
<Fields>
<Field Name="KeepsParameters" BitMask="0001">
<Description>If KeepsParameters is not set, the device will lose its configuration during update. The Client should do a backup of the parameters before the update and restore them afterwards.</Description>
</Field>
<Field Name="WillDisconnect" BitMask="0002">
<Description>If WillDisconnect is set, the OPC UA Server will restart during installation. This can be the case if the update is about the firmware of the device that hosts the OPC UA Server.</Description>
</Field>
<Field Name="RequiresPowerCycle" BitMask="0004">
<Description>If RequiresPowerCycle is set, the devices require a manual power off / power on for installation.</Description>
</Field>
<Field Name="WillReboot" BitMask="0008">
<Description>If WillReboot is set, the device will reboot during the update, inclusive of embedded infrastructure elements like an integrated switch. An update Client should take this into account since the devices behind an integrated switch are not reachable for that time.</Description>
</Field>
<Field Name="NeedsPreparation" BitMask="0010">
<Description>If NeedsPreparation is not set, the Client can install the update without maintaining the PrepareForUpdateStateMachine. This can be used to support an installation without stopping the software.</Description>
</Field>
</Fields>
</DataType>

Avatar
Paul Hunkar
Cleveland, Ohio, USA
Moderator
Members

Moderators-Specifications

Moderators-Companion

Moderators-Implementation

Moderators-Certification

Moderators-COM
Forum Posts: 112
Member Since:
02/24/2014
sp_UserOfflineSmall Offline
6
06/11/2022 - 19:54
sp_Permalink sp_Print

The OPC Foundation specification define OptionSet in two manners, depending on the use case.  There is an OptionSet datatype that is a subtype of structure which is composed of two bytestrings (one for value and one for valid bits).  There is an OptionSetType VariableType which can be used for the same purpose. As a guideline the DataType would bused when the bit mask is fixed and applies to several Variables. The VariableType would be used when the bit mask is specific for only that Variable.  The VariableType allows the value to be any of a number of datatypes (this includes integers),  what Randy showed is the definition of an optionset that is a subtype of integer.

Paul Hunkar - DSInteroperability

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