openpectus.engine.hardware

Attributes

logger

Exceptions

HardwareLayerException

Raised when hardware connection issues occur.

Classes

RegisterDirection

Support for flags

Register

Represents a hardware register or named value.

HardwareLayerBase

Base class for hardware layer implementations.

NullHardware

Represents no hardware. Used by tests.

Module Contents

openpectus.engine.hardware.logger
class openpectus.engine.hardware.RegisterDirection(*args, **kwds)

Bases: enum.Flag

Support for flags

Read
Write
Both
class openpectus.engine.hardware.Register(name, direction, **options)

Represents a hardware register or named value.

Parameters:
_name: str
_direction: RegisterDirection
_options: dict[str, Any]
property name
property direction: RegisterDirection
Return type:

RegisterDirection

property options: dict[str, Any]
Return type:

dict[str, Any]

__str__()
Return type:

str

__repr__()
exception openpectus.engine.hardware.HardwareLayerException(message, ex=None)

Bases: Exception

Raised when hardware connection issues occur.

Parameters:
  • message (str)

  • ex (Exception | None)

message
ex = None
__str__()

Return str(self).

Return type:

str

class openpectus.engine.hardware.HardwareLayerBase

Base class for hardware layer implementations.

_registers: dict[str, Register]
_is_connected: bool = False
__enter__()

Allow use as context manager.

__exit__(type, value, traceback)
tick()

Invoked on each tick by engine.

__str__()
Return type:

str

property registers: dict[str, Register]
Return type:

dict[str, Register]

property is_connected: bool

Returns a value indicating whether there is an active connection to the hardware. Virtual property.

Return type:

bool

read(r)

Read single register value. Abstract method.

Parameters:

r (Register)

Return type:

Any

read_batch(registers)

Read batch of register values. Override to provide efficient implementation. Virtual method.

Parameters:

registers (Sequence[Register])

Return type:

list[Any]

write(value, r)

Write single register value. Abstract method.

Parameters:
Return type:

None

write_batch(values, registers)

Write batch of register values. Override to provide efficient implementation. Virtual method.

Parameters:
  • values (Sequence[Any])

  • registers (Sequence[Register])

connect()

Connect to hardware. Throw HardwareLayerException on error. Virtual method. Implementations must call base method on completed connect.

disconnect()

Disconnect from hardware. Throw HardwareLayerException on error. Virtual method. Implementations must call base method on completed disconnect.

reconnect()

Perform a reconnect. The default implementation just disconnects (ignoring any error) and connects. Override to perform a more advanced reconnect, like using a thread.

validate_offline()

Perform checks that verify that the registers definition is valid. Raise on validation error. Virtual method.

validate_online()

Perform checks that verify online hardware access. Raise on validation error. Virtual method.

The default implementation checks that all Read registers can be read. Override to add additional checks.

show_online_register_details()

Displays online register details to use in uod definition.

class openpectus.engine.hardware.NullHardware

Bases: HardwareLayerBase

Represents no hardware. Used by tests.

_is_connected = True
__str__()
Return type:

str

read(r)

Read single register value. Abstract method.

Parameters:

r (Register)

Return type:

Any

write(value, r)

Write single register value. Abstract method.

Parameters:
__getattribute__(name)
Parameters:

name (str)

Return type:

Any