plesty.lib.sim.apt

In-memory simulator of an APT motor controller.

AptMotorSimulator mimics the serial-port interface used by plesty.lib.traffic.apt.AptTrafficManager (write / read / in_waiting / buffer resets) and answers APT motor messages like a single-channel stage: homing and moves complete instantly, parameter sets are stored and echoed back on request.

Attributes

_SIM_SERIAL_NUMBER

_SIM_MODEL

Classes

AptMotorSimulator

Serial-like, single-channel APT motor controller simulator.

Module Contents

plesty.lib.sim.apt._SIM_SERIAL_NUMBER = 55123456
plesty.lib.sim.apt._SIM_MODEL = b'SIM-APT\x00'
class plesty.lib.sim.apt.AptMotorSimulator

Serial-like, single-channel APT motor controller simulator.

position: int = 0

Current position counter in device counts.

homed: bool = False

Whether the simulated stage has been homed.

channel: int = 1

The single supported channel number.

_recv_state: plesty.lib.traffic.apt_protocol.AptRecvState
_out: bytearray
_params: dict[plesty.lib.traffic.apt_protocol.AptMessageId, bytes]
_closed: bool = False
property is_open: bool

Return True while the simulated port is open.

Return type:

bool

property in_waiting: int

Number of reply bytes waiting to be read.

Return type:

int

write(data: bytes) int

Receive raw bytes from the host and process complete messages.

Parameters:

data (bytes)

Return type:

int

read(size: int) bytes

Return up to size pending reply bytes.

Parameters:

size (int)

Return type:

bytes

reset_input_buffer() None

Drop all pending reply bytes.

Return type:

None

reset_output_buffer() None

No-op; the simulator has no outgoing host buffer.

Return type:

None

flush() None

No-op; writes are processed immediately.

Return type:

None

close() None

Close the simulated port.

Return type:

None

_reply(message: plesty.lib.traffic.apt_protocol.AptMessage, message_id: plesty.lib.traffic.apt_protocol.AptMessageId, payload: bytes) None

Queue a reply message mirroring the incoming addressing.

Parameters:
Return type:

None

_status_bits() plesty.lib.traffic.apt_protocol.AptStatusBits

Return the current status word.

Return type:

plesty.lib.traffic.apt_protocol.AptStatusBits

_status_update() bytes

Return a single-channel StatusUpdate payload.

Return type:

bytes

_handle(message: plesty.lib.traffic.apt_protocol.AptMessage) None

Dispatch one received message to the device model.

Parameters:

message (plesty.lib.traffic.apt_protocol.AptMessage)

Return type:

None