openpectus.lang.exec.tags

Attributes

TagValueType

Represents the types of tag values

TagFormatFunction

Represents a function that is used to format tag values for display

Classes

SystemTagName

Enum where members are also (and must be) strings

ChangeListener

Collects named changes. Used by engine to track tag changes

ChangeSubject

Inherit to support change notification. Used by engine to track tag changes

TagDirection

Specifies whether a tag is read from or written to hardware and whether is can be changed in UI.

Unset

Used to specify that a value has not been set.

Tag

Base class for tags. Most tags do not need their own class but can just use this class.

TagCollection

Represents a name/tag dictionary.

TagValue

Read-only and immutable representation of a tag value.

TagValueCollection

Represents a read-only and immutable dictionary of tag values.

Functions

format_time_as_clock(value)

create_system_tags()

Module Contents

class openpectus.lang.exec.tags.SystemTagName

Bases: enum.StrEnum

Enum where members are also (and must be) strings

BASE = 'Base'
RUN_COUNTER = 'Run Counter'
BLOCK = 'Block'
BLOCK_TIME = 'Block Time'
SCOPE_TIME = 'Scope Time'
PROCESS_TIME = 'Process Time'
RUN_TIME = 'Run Time'
CLOCK = 'Clock'
SYSTEM_STATE = 'System State'
METHOD_STATUS = 'Method Status'
CONNECTION_STATUS = 'Connection Status'
RUN_ID = 'Run Id'
BATCH_NAME = 'Batch Name'
MARK = 'Mark'
ARCHIVER = 'Archive filename'
BLOCK_VOLUME = 'Block Volume'
ACCUMULATED_VOLUME = 'Accumulated Volume'
BLOCK_CV = 'Block CV'
ACCUMULATED_CV = 'Accumulated CV'
static has_value(value)

Determine if enum has this string value defined. Case sensitive.

Parameters:

value (str)

openpectus.lang.exec.tags.TagValueType

Represents the types of tag values

openpectus.lang.exec.tags.TagFormatFunction

Represents a function that is used to format tag values for display

openpectus.lang.exec.tags.format_time_as_clock(value)
Parameters:

value (float)

Return type:

str

class openpectus.lang.exec.tags.ChangeListener

Collects named changes. Used by engine to track tag changes

_changes: Set[str]
__str__()
Return type:

str

notify_change(elm)
Parameters:

elm (str)

clear_changes()
property changes: list[str]
Return type:

list[str]

class openpectus.lang.exec.tags.ChangeSubject

Inherit to support change notification. Used by engine to track tag changes

_listeners: list[ChangeListener] = []
__str__()
Return type:

str

add_listener(listener)
Parameters:

listener (ChangeListener)

notify_listeners(elm)
Parameters:

elm (str)

clear_listeners()
class openpectus.lang.exec.tags.TagDirection

Bases: enum.StrEnum

Specifies whether a tag is read from or written to hardware and whether is can be changed in UI.

Direction of the tag is in relation to the physical IO. Sensors are regarded as inputs and actuators as outputs. Derived values are regarded as NA.

Input

Tag is read from hardware, e.g. a sensor

Output

Tag is written to hardware, e.g. an actuator

NA

Tag is calculated/derived and neither read from or written to hw.

Unspecified
class openpectus.lang.exec.tags.Unset

Used to specify that a value has not been set.

Used for nullable values to distinguish between being set to None and not being set.

__str__()
Return type:

str

class openpectus.lang.exec.tags.Tag(name, tick_time=None, value=None, unit=None, direction=TagDirection.NA, format_fn=None)

Bases: ChangeSubject, openpectus.lang.exec.events.EventListener

Base class for tags. Most tags do not need their own class but can just use this class.

Supports change tracking which is used by engine to detect changes between reads of hardware values.

Supports lifetime notification events that are automatically invoked by the engine.

Supports masking the actual value with a simulated value.

Parameters:
  • name (str)

  • tick_time (float | None)

  • value (TagValueType)

  • unit (str | None)

  • direction (TagDirection)

  • format_fn (TagFormatFunction | None)

name: str
tick_time
value: TagValueType = None
unit: str | None = None
choices: list[str] | None = None
direction: TagDirection
format_fn = None
simulated_value: TagValueType = None
simulated: bool = False
__str__()
Return type:

str

as_readonly()

Convert the value to a readonly and immutable TagValue instance

Return type:

TagValue

set_value(val, tick_time)
Parameters:
  • val (TagValueType)

  • tick_time (float)

Return type:

None

set_value_and_unit(val, unit, tick_time)

Set a new value by converting the provided value and unit into the the unit of the tag.

Parameters:
  • val (TagValueType)

  • unit (str)

  • tick_time (float)

Return type:

None

simulate_value_and_unit(val, unit, tick_time)

Set a simulated value by converting the provided value and unit into the the unit of the tag.

Parameters:
  • val (TagValueType)

  • unit (str)

  • tick_time (float)

Return type:

None

simulate_value(val, tick_time)
Parameters:
  • val (TagValueType)

  • tick_time (float)

stop_simulation()
get_value()
as_number()
Return type:

int | float

as_float()
Return type:

float

archive()

The value to write to archive or None to skip that tag from archival

Return type:

str | None

on_stop()

Is invoked by the Stop command when method is stopped.

class openpectus.lang.exec.tags.TagCollection(tags=None)

Bases: ChangeSubject, ChangeListener, Iterable[Tag]

Represents a name/tag dictionary.

Parameters:

tags (Iterable[Tag] | None)

tags: dict[str, Tag]
__str__()
Return type:

str

as_readonly()
Return type:

TagValueCollection

notify_change(elm)
Parameters:

elm (str)

property names: list[str]

Return the tag names

Return type:

list[str]

__iter__()
__getitem__(tag_name)
Parameters:

tag_name (str)

Return type:

Tag

__len__()
Return type:

int

get(tag_name)
Parameters:

tag_name (str)

Return type:

Tag

add(tag, exist_ok=True)

Add tag to collection. If tag name already exists and exist_ok is False, a ValueError is raised.

Parameters:
  • tag (Tag)

  • exist_ok (bool)

with_tag(tag)
Parameters:

tag (Tag)

has(tag_name)
Parameters:

tag_name (str)

Return type:

bool

get_value_or_default(tag_name)
Return type:

TagValueType

merge_with(other)

Returns a new TagCollection with the combined tags of both collections.

Tag instances are kept so tag values are shared between the three collections.

In case of duplicate tag names, tags from other collection are used.

Parameters:

other (TagCollection)

Return type:

TagCollection

class openpectus.lang.exec.tags.TagValue(name, tick_time=0.0, value=None, value_formatted=None, unit=None, direction=TagDirection.Unspecified, simulated=None)

Read-only and immutable representation of a tag value.

Parameters:
  • name (str)

  • tick_time (float)

  • value (TagValueType)

  • value_formatted (str | None)

  • unit (str | None)

  • direction (TagDirection)

  • simulated (bool | None)

name
tick_time = 0.0
value = None
value_formatted = None
unit = None
direction
simulated = None
__str__()
Return type:

str

clone()
Return type:

TagValue

class openpectus.lang.exec.tags.TagValueCollection(values)

Bases: Iterable[TagValue]

Represents a read-only and immutable dictionary of tag values.

Parameters:

values (Iterable[TagValue])

_tag_values: dict[str, TagValue]
__str__()
Return type:

str

static empty()
Return type:

TagValueCollection

property names: list[str]

Return the tag names

Return type:

list[str]

get(tag_name)
Parameters:

tag_name (str)

Return type:

TagValue

has(tag_name)
Parameters:

tag_name (str)

Return type:

bool

_add(tag_value)
Parameters:

tag_value (TagValue)

__iter__()
__getitem__(tag_name)
Parameters:

tag_name (str)

Return type:

TagValue

__len__()
Return type:

int

to_list()
Return type:

list[TagValue]

clone()
Return type:

TagValueCollection

openpectus.lang.exec.tags.create_system_tags()
Return type:

TagCollection