Skip to content

Basic Abstractions

This section covers the core abstract classes that serve as the foundation for all specific protocol implementations in AQPXLIB.

Abstract Bus

The PxAbstractBus class defines the common interface for all protocol buses. It handles:

  • Electrical configuration (voltage, pull-ups, etc.)
  • Device attachment and management
  • Common bus operations

PxAbstractBus

PxAbstractBus(exerciser: AqProtocolExerciser)

Abstract Bus Class for all bus types.

METHOD DESCRIPTION
add_event_handler

Add an event handler to the current bus instance.

attach_controller

Attach a controller to the bus.

attach_target

Attach a target to the bus.

create_device

Create a new device on the bus.

get_config

Get the configuration of the bus.

get_controller_pb_msg

Get the configuration of the controller from the bus.

get_controllers

Get the controllers of the bus.

get_device_pb_msg

Get the configuration of the device from the bus.

get_device_state

Get the state of the device from the bus.

get_devices

Get the devices of the bus.

get_target_pb_msg

Get the configuration of the target from the bus.

get_targets

Get the targets of the bus.

remove_controller

Remove a controller from the bus.

remove_device

Remove a device from the bus.

remove_target

Remove a target from the bus.

set_config

Set the configuration of the bus.

set_device_state

Set the state of the device on the bus.

ATTRIBUTE DESCRIPTION
available_devices_by_identifier

A mapping of device identifier (from abstract instance) to device classes.

TYPE: dict[str, type[PxAbstractDevice]]

available_devices_by_protobuf_key

A mapping of device protobuf field name to device classes.

TYPE: dict[str, type[PxAbstractDevice]]

bus_hold_enable

The bus hold enable of the bus.

TYPE: bool | None

handle_index

The index of the bus interface.

TYPE: int

la_threshold_voltage

The la threshold voltage of the bus.

TYPE: int | None

pulldown_resistance

The pulldown resistance of the bus.

TYPE: int | None

pullup_resistance

The pullup resistance of the bus.

TYPE: int | None

voltage

The voltage of the bus.

TYPE: int | None

available_devices_by_identifier

available_devices_by_identifier: dict[str, type[PxAbstractDevice]]

A mapping of device identifier (from abstract instance) to device classes.

available_devices_by_protobuf_key

available_devices_by_protobuf_key: dict[str, type[PxAbstractDevice]]

A mapping of device protobuf field name to device classes.

bus_hold_enable

bus_hold_enable: bool | None

The bus hold enable of the bus.

handle_index

handle_index: int

The index of the bus interface.

la_threshold_voltage

la_threshold_voltage: int | None

The la threshold voltage of the bus.

pulldown_resistance

pulldown_resistance: int | None

The pulldown resistance of the bus.

pullup_resistance

pullup_resistance: int | None

The pullup resistance of the bus.

voltage

voltage: int | None

The voltage of the bus.

add_event_handler

add_event_handler(event: str, handler: Callable[[Any], Any]) -> None

Add an event handler to the current bus instance.

attach_controller

attach_controller(controller: PxAbstractDevice) -> None

Attach a controller to the bus.

attach_target

attach_target(target: PxAbstractDevice) -> None

Attach a target to the bus.

create_device

create_device(
    exerciser: AqProtocolExerciser, device_identifier: str, *args, **kwargs
) -> PxAbstractDevice

Create a new device on the bus.

A new device interface will be created and attached to the bus.

PARAMETER DESCRIPTION

exerciser

An exerciser instance which is used to send request to server

TYPE: AqProtocolExerciser

device_identifier

The unique identifier of the device to create

TYPE: str

*args

Additional arguments to pass to the device constructor

DEFAULT: ()

**kwargs

Additional keyword arguments to pass to the device constructor

DEFAULT: {}

RETURNS DESCRIPTION
PxAbstractDevice

The interface of the created device

TYPE: PxAbstractDevice

RAISES DESCRIPTION
ValueError

If the device_identifier is not supported

get_config

get_config() -> PxHandle | None

Get the configuration of the bus.

get_controller_pb_msg

get_controller_pb_msg(controller: PxAbstractDevice) -> Message | None

Get the configuration of the controller from the bus.

get_controllers

get_controllers() -> list[PxAbstractDevice]

Get the controllers of the bus.

get_device_pb_msg

get_device_pb_msg(device: PxAbstractDevice) -> Message | None

Get the configuration of the device from the bus.

get_device_state

get_device_state(device: PxAbstractDevice) -> Message | None

Get the state of the device from the bus.

get_devices

get_devices() -> list[PxAbstractDevice]

Get the devices of the bus.

get_target_pb_msg

get_target_pb_msg(target: PxAbstractDevice) -> Message | None

Get the configuration of the target from the bus.

get_targets

get_targets() -> list[PxAbstractDevice]

Get the targets of the bus.

remove_controller

remove_controller(controller: PxAbstractDevice) -> None

Remove a controller from the bus.

remove_device

remove_device(device: PxAbstractDevice) -> None

Remove a device from the bus.

remove_target

remove_target(target: PxAbstractDevice) -> None

Remove a target from the bus.

set_config

set_config(config: PxHandle) -> PxHandle

Set the configuration of the bus.

set_device_state

set_device_state(device: PxAbstractDevice, state: Message) -> None

Set the state of the device on the bus.

Abstract Device

The PxAbstractDevice class is the base for all emulated devices (controllers and targets). It provides:

  • Device identification and configuration
  • State management
  • Event handling

PxAbstractDevice

PxAbstractDevice(
    exerciser: AqProtocolExerciser,
    bus: Optional[PxAbstractBus] = None,
    name: str = "",
    device_id: int = 0,
    config: Message | None = None,
)

Abstract Device Class for all device types.

This class defines methods that are common to all device types.

METHOD DESCRIPTION
add_event_handler

Add an event handler to the current device instance.

detach_from_bus

Detach the device from the bus.

get_event_handlers

Retreive handlers registerd on this device.

perform_operation

Send an operation.

ATTRIBUTE DESCRIPTION
config

Get the config of the device.

TYPE: Message | None

is_attached

Check if the device is attached to a bus.

TYPE: bool

name

Get the name of the device.

TYPE: str

state

Get the state of the device.

TYPE: Message | None

config

config: Message | None

Get the config of the device.

is_attached

is_attached: bool

Check if the device is attached to a bus.

name

name: str

Get the name of the device.

state

state: Message | None

Get the state of the device.

add_event_handler

add_event_handler(event: str, handler: Callable[[Any], Any]) -> None

Add an event handler to the current device instance.

detach_from_bus

detach_from_bus() -> None

Detach the device from the bus.

The opposite of the attach_to_bus method.

get_event_handlers

get_event_handlers() -> dict[str, Callable]

Retreive handlers registerd on this device.

perform_operation

perform_operation(operation: PxDeviceOperation) -> PxDeviceOperation

Send an operation.