BaseLabJackDataClient

class lsst.ts.ess.labjack.BaseLabJackDataClient(config: SimpleNamespace, topics: Controller | SimpleNamespace, log: Logger, simulation_mode: int = 0)

Bases: BaseReadLoopDataClient, ABC

Base class for ESS data clients that read a LabJack T7 or similar.

Parameters:
namestr
configtypes.SimpleNamespace

The configuration, after validation by the schema returned by get_config_schema and conversion to a types.SimpleNamespace.

topicssalobj.Controller

The telemetry topics this model can write, as a struct with attributes such as tel_temperature.

loglogging.Logger

Logger.

simulation_modeint, optional

Simulation mode; 0 for normal operation.

Notes

In simulation mode the mock LabJack returns unspecified values, and those values may change in future versions of the LabJack software.

Attributes Summary

connected

Methods Summary

connect()

Connect to the LabJack.

descr()

Return a brief description, without the class name.

disconnect()

Disconnect from the LabJack.

get_config_schema()

Get the config schema as jsonschema dict.

read_data()

Read data.

read_data_once()

read_loop()

Call the read_data method in a loop.

run()

Read data from the server and publish it as ESS telemetry.

run_in_thread(func, timeout)

Run a blocking function in a thread pool executor.

setup_reading()

Perform any tasks before starting the read loop.

start()

Override start method to handle auto reconnecting if necessary.

start_tasks()

Call disconnect, connect, and start the run task.

stop()

Delegate handling of stop tasks to the stop_tasks method.

stop_tasks()

Stop reading and publishing data.

Attributes Documentation

connected

Methods Documentation

async connect() None

Connect to the LabJack.

Disconnect first, if connected.

Raises:
RuntimeError

If we cannot read the data.

descr() str

Return a brief description, without the class name.

This should be just enough information to distinguish one instance of this client from another. For example RPiDataClient should return something like:

f"host={self.config.host}, port={self.config.port}"
async disconnect() None

Disconnect from the LabJack. A no-op if disconnected.

abstract classmethod get_config_schema() dict[str, Any]

Get the config schema as jsonschema dict.

abstract async read_data() None

Read data.

Notes

This method needs to raise an asyncio.TimeoutError when timing out, otherwise the read_loop method may hang forever.

async read_data_once() None
async read_loop() None

Call the read_data method in a loop.

Allow for max_timeouts timeouts before raising a TimeoutError.

async run() None

Read data from the server and publish it as ESS telemetry.

This is called once after connect and it should keep running until cancelled. See the Raises section for exceptions subclasses should raise.

Raises:
ConnectionError

If the connection to the data server is lost.

asyncio.TimeoutError

If data is not received in reasonable time.

Exception

(or any subclass) if any other serious problem occurs.

async run_in_thread(func: Callable[[], Any], timeout: float) Any

Run a blocking function in a thread pool executor.

Only one function will run at a time, because all calls use the same thread pool executor, which only has a single thread.

Parameters:
funcCallable

The blocking function to run; The function must take no arguments. For example: self._blocking_connect.

timeoutfloat

Time limit (seconds).

async setup_reading() None

Perform any tasks before starting the read loop.

async start() None

Override start method to handle auto reconnecting if necessary.

async start_tasks() None

Call disconnect, connect, and start the run task.

Raises the same exceptions as connect. If disconnect raises, this logs the exception and continues.

async stop() None

Delegate handling of stop tasks to the stop_tasks method.

This allows implementing classes to customize stop behavior.

async stop_tasks() None

Stop reading and publishing data.

This is alway safe to call, whether connected or not. This should raise no exceptions except asyncio.CancelledError. If disconnect raises, this logs the exception and continues.