Skip to content

optionsetbit

Canonical path: o6.optionsetbit

optionsetbit

optionsetbit(position, *, name=None)

Declare one bit of a structure-form OPC UA OptionSet.

Used as the assigned value of an attribute in an @o6.datatype class body that subtypes the ns0 OptionSet, alongside its Value and ValidBits members. position is the bit's position, exactly as the NodeSet Definition declares it — the low byte of Value first, least significant bit first.

@o6.datatype(ns="plant")
class ExplosionZoneOptionSet(ns0.datatypes.OptionSet):
    value: o6.ByteString
    validBits: o6.ByteString

    zone0 = o6.optionsetbit(0, name="Zone 0")
    zone1 = o6.optionsetbit(1, name="Zone 1")

Reading the attribute is three-valued: True when the bit is set and valid, False when it is clear and valid, and None when ValidBits says the bit means nothing — including when ValidBits is too short to reach it. Assigning True or False updates Value and ValidBits together, so an inconsistent pair cannot be produced through the accessor; assigning None makes the bit not valid again.

This is the structure form of an OptionSet. The integer form is declared with @o6.optionsettype and o6.bitmask instead; the two share a name and nothing else.

Parameters:

Name Type Description Default
position int

Bit position within the Value ByteString.

required
name Optional[str]

OPC UA bit name, for a UA name that is not a valid Python identifier.

None

Returns:

Type Description
Any

An accessor for the declared bit.

Raises:

Type Description
ValueError

The bit position is negative.