magscope.hardware#

Classes#

HardwareManagerBase

Abstract base class for processes in the MagScope

FocusMotorBase

Base class for absolute-Z focus motors used by MagScope.

Module Contents#

class magscope.hardware.HardwareManagerBase[source]#

Bases: magscope.processes.ManagerProcessBase, abc.ABC

Abstract base class for processes in the MagScope

Subclass requirements: * Each subclass should have a unique name. * There should only be one instance of each subclass (singleton). * The class name is used for consistent inter-process identification.

buffer_shape = (1000, 2)[source]#
_buffer: magscope.datatypes.MatrixBuffer | None = None[source]#
_is_connected: bool = False[source]#
setup()[source]#
do_main_loop()[source]#
quit()[source]#

Shutdown the process (and ask the other processes to quit too).

abstractmethod connect()[source]#
abstractmethod disconnect()[source]#
abstractmethod fetch()[source]#

Checks if the hardware has new data.

If the hardware has new data, then it stores the data and timestamp in the matrix buffer (self._buffer).

The timestamp should be the seconds since the unix epoch: (January 1, 1970, 00:00:00 UTC)

_save_pending_data_if_enabled() None[source]#
_hardware_save_filepath() pathlib.Path[source]#
_hardware_save_header() str[source]#
class magscope.hardware.FocusMotorBase[source]#

Bases: HardwareManagerBase, abc.ABC

Base class for absolute-Z focus motors used by MagScope.

Subclasses provide the device-specific motion primitives while this base class standardizes polling, telemetry buffering, and the optional bridge to the simulated camera. The hardware matrix buffer stores rows as [timestamp, current_z, target_z, is_at_target] where is_at_target is encoded as 0.0 or 1.0.

at_target_tolerance = 10[source]#
buffer_shape = (100000, 4)[source]#
fetch_interval = 0.05[source]#
_target_z = 0.0[source]#
_last_written = 0.0[source]#
_last_sent_focus: float | None = None[source]#
_last_state: tuple[float, float, bool] | None = None[source]#
setup()[source]#
fetch()[source]#

Checks if the hardware has new data.

If the hardware has new data, then it stores the data and timestamp in the matrix buffer (self._buffer).

The timestamp should be the seconds since the unix epoch: (January 1, 1970, 00:00:00 UTC)

handle_move_absolute(z: float)[source]#
report_focus_motor_limits() None[source]#
get_target_z() float[source]#
is_at_target(tolerance: float | None = None) bool[source]#
_write_state(timestamp: float, current_z: float, *, force: bool = False) None[source]#
_poll_hardware(now: float) None[source]#

Allow subclasses to advance device state before telemetry is sampled.

_update_simulated_camera_focus(current_z: float, *, force: bool = False) None[source]#
abstractmethod move_absolute(z: float) None[source]#

Command the motor to move to an absolute Z position.

abstractmethod get_current_z() float[source]#

Return the motor’s reported current Z position.

abstractmethod get_is_moving() bool[source]#

Return the motor’s reported moving state.

abstractmethod get_position_limits() tuple[float, float][source]#

Return the allowed absolute Z limits for this motor.