plesty.lib.sim.apt ================== .. py:module:: plesty.lib.sim.apt .. autoapi-nested-parse:: In-memory simulator of an APT motor controller. :class:`AptMotorSimulator` mimics the serial-port interface used by :class:`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 ---------- .. autoapisummary:: plesty.lib.sim.apt._SIM_SERIAL_NUMBER plesty.lib.sim.apt._SIM_MODEL Classes ------- .. autoapisummary:: plesty.lib.sim.apt.AptMotorSimulator Module Contents --------------- .. py:data:: _SIM_SERIAL_NUMBER :value: 55123456 .. py:data:: _SIM_MODEL :value: b'SIM-APT\x00' .. py:class:: AptMotorSimulator Serial-like, single-channel APT motor controller simulator. .. py:attribute:: position :type: int :value: 0 Current position counter in device counts. .. py:attribute:: homed :type: bool :value: False Whether the simulated stage has been homed. .. py:attribute:: channel :type: int :value: 1 The single supported channel number. .. py:attribute:: _recv_state :type: plesty.lib.traffic.apt_protocol.AptRecvState .. py:attribute:: _out :type: bytearray .. py:attribute:: _params :type: dict[plesty.lib.traffic.apt_protocol.AptMessageId, bytes] .. py:attribute:: _closed :type: bool :value: False .. py:property:: is_open :type: bool Return True while the simulated port is open. .. py:property:: in_waiting :type: int Number of reply bytes waiting to be read. .. py:method:: write(data: bytes) -> int Receive raw bytes from the host and process complete messages. .. py:method:: read(size: int) -> bytes Return up to ``size`` pending reply bytes. .. py:method:: reset_input_buffer() -> None Drop all pending reply bytes. .. py:method:: reset_output_buffer() -> None No-op; the simulator has no outgoing host buffer. .. py:method:: flush() -> None No-op; writes are processed immediately. .. py:method:: close() -> None Close the simulated port. .. py:method:: _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. .. py:method:: _status_bits() -> plesty.lib.traffic.apt_protocol.AptStatusBits Return the current status word. .. py:method:: _status_update() -> bytes Return a single-channel ``StatusUpdate`` payload. .. py:method:: _handle(message: plesty.lib.traffic.apt_protocol.AptMessage) -> None Dispatch one received message to the device model.