Skip to content

Basic Abstractions

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

For instrument-level GPIO (read/drive/pulse/trigger), see GPIO.

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
get_config

Get the configuration of the bus.

get_target_pb_msg

Get the configuration of the target from the bus.

get_controller_pb_msg

Get the configuration of the controller from the bus.

remove_controller

Remove a controller from the bus.

remove_target

Remove a target from the bus.

remove_device

Remove a device from the bus.

get_device_state

Get the state of the device from the bus.

set_device_state

Set the state of the device on the bus.

get_device_pb_msg

Get the configuration of the device from the bus.

set_config

Set the configuration of the bus.

get_controllers

Get the controllers of the bus.

attach_controller

Attach a controller to the bus.

attach_target

Attach a target to the bus.

get_targets

Get the targets of the bus.

get_devices

Get the devices of the bus.

create_device

Create a new device on the bus.

add_event_handler

Add an event handler to the current bus instance.

ATTRIBUTE DESCRIPTION
available_devices_by_protobuf_key

A mapping of device protobuf field name to device classes.

TYPE: dict[str, type[PxAbstractDevice]]

available_devices_by_identifier

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

TYPE: dict[str, type[PxAbstractDevice]]

handle_index

The index of the bus interface.

TYPE: int

voltage

The voltage of the bus.

TYPE: int | None

la_threshold_voltage

The la threshold voltage of the bus.

TYPE: int | None

pullup_resistance

The pullup resistance of the bus.

TYPE: int | None

pulldown_resistance

The pulldown resistance of the bus.

TYPE: int | None

bus_hold_enable

The bus hold enable of the bus.

TYPE: bool | None

available_devices_by_protobuf_key

available_devices_by_protobuf_key: dict[str, type[PxAbstractDevice]]

A mapping of device protobuf field name to device classes.

available_devices_by_identifier

available_devices_by_identifier: dict[str, type[PxAbstractDevice]]

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

handle_index

handle_index: int

The index of the bus interface.

voltage

voltage: int | None

The voltage of the bus.

la_threshold_voltage

la_threshold_voltage: int | None

The la threshold voltage of the bus.

pullup_resistance

pullup_resistance: int | None

The pullup resistance of the bus.

pulldown_resistance

pulldown_resistance: int | None

The pulldown resistance of the bus.

bus_hold_enable

bus_hold_enable: bool | None

The bus hold enable of the bus.

get_config

get_config() -> PxHandle | None

Get the configuration 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_controller_pb_msg

get_controller_pb_msg(controller: PxAbstractDevice) -> Message | None

Get the configuration of the controller from the bus.

remove_controller

remove_controller(controller: PxAbstractDevice) -> None

Remove a controller from the bus.

remove_target

remove_target(target: PxAbstractDevice) -> None

Remove a target from the bus.

remove_device

remove_device(device: PxAbstractDevice) -> None

Remove a device from the bus.

get_device_state

get_device_state(device: PxAbstractDevice) -> Message | None

Get the state of the device from the bus.

set_device_state

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

Set the state of the device on the bus.

get_device_pb_msg

get_device_pb_msg(device: PxAbstractDevice) -> Message | None

Get the configuration of the device from the bus.

set_config

set_config(config: PxHandle) -> PxHandle

Set the configuration of the bus.

get_controllers

get_controllers() -> list[PxAbstractDevice]

Get the controllers of the bus.

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.

get_targets

get_targets() -> list[PxAbstractDevice]

Get the targets of the bus.

get_devices

get_devices() -> list[PxAbstractDevice]

Get the devices of the bus.

create_device

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

add_event_handler

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

Add an event handler to the current bus instance.

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 = "",
    cts_op_name: str | None = None,
    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
detach_from_bus

Detach the device from the bus.

perform_operation

Send an operation.

add_event_handler

Add an event handler to the current device instance.

get_event_handlers

Retreive handlers registerd on this device.

ATTRIBUTE DESCRIPTION
is_attached

Check if the device is attached to a bus.

TYPE: bool

state

Get the state of the device.

TYPE: Message | None

name

Get the name of the device.

TYPE: str

config

Get the config of the device.

TYPE: Message | None

is_attached

is_attached: bool

Check if the device is attached to a bus.

state

state: Message | None

Get the state of the device.

name

name: str

Get the name of the device.

config

config: Message | None

Get the config of the device.

detach_from_bus

detach_from_bus() -> None

Detach the device from the bus.

The opposite of the attach_to_bus method.

perform_operation

perform_operation(operation: PxDeviceOperation) -> PxDeviceOperation

Send an operation.

add_event_handler

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

Add an event handler to the current device instance.

get_event_handlers

get_event_handlers() -> dict[str, Callable]

Retreive handlers registerd on this device.