class labterm.instrument.Instrument(channel: int)[source]#

Bases: ABC

Abstract base class for all instruments connected to the dashboard.

Concrete subclasses must implement update_data() and action(). The Dashboard expects each instrument to expose a data dict and an optional logger callable.

Parameters:

channel (int) – Unique channel id identifying the instrument.

Variables:
  • data (dict[str, Any]) – Live instrument data. Keys and value types are instrument-specific. Dashboard items update their values from this dictionary.

  • logger (Optional[Callable[[str], None]]) – Optional logging callback set by the Dashboard via instrument.logger = self._log.

Examples

>>> class MyInstrument(Instrument):
...     def __init__(self, channel):
...         super().__init__(channel)
...         self.data = {'voltage': None}
...     def update_data(self):
...         self.data['voltage'] = 3.3
abstractmethod action(action_id: str, *args: Any) None[source]#

Handle an action request from a DashboardItem.

Implementations should perform the action or raise a clear exception.

Parameters:
  • action_id (str) – Identifier for the requested action (e.g. “set_voltage”).

  • *args – Additional action arguments.

Raises:
  • ValueError – If arguments are invalid for the requested action.

  • RuntimeError – If the action could not be completed.

abstractmethod update_data() None[source]#

Refresh data with current instrument values.

This method is called periodically from a Dashboard background thread.

Raises:

Exception – Propagate exceptions if communication fails; Dashboard will catch and log them.