Controllers
- PyLabware.controllers.in_simulation_device_returns(value)[source]
Decorator that patched the device send() method to return the value passed.
- class PyLabware.controllers.LabDevice(device_name=None, connection_mode=None, connection_parameters=None)[source]
Bases:
AbstractLabDevice
Base controller class for all labware devices.
Default constructor. This function performs object initialization. All device-specific hardware initialization procedures should be inside the
initialise_device()
method.This method has to be redefined in child classes.
- Parameters:
device_name (
str
) – Device name (for logging purposes).connection_mode (
str
) – Physical connection mode (defines the connection adapter used).connection_parameters (
Dict
) – Dictionary with connection-specific settings. These vary depending on the connection_mode.
- cast_reply_type(cmd, reply)[source]
Casts reply type based on the type provided in command definition.
- Parameters:
reply (
Any
) – Reply string.cmd (
Dict
) – Command definition to look the type value in.
- Returns:
Reply casted to the correct type.
- Return type:
(any)
- check_value(cmd, value)[source]
Checks the value provided against the definitions in command dict. Then does any value conversion/formatting/type casting as needed.
This method may be redefined in child classes.
- Parameters:
cmd (
Dict
) – Device command definition.value (
Any
) – Command parameter to check.
- Returns:
Processed value.
- Return type:
(Any)
- connect()[source]
Connects to the device.
This method normally shouldn’t be redefined in child classes.
- disconnect()[source]
Disconnects from the device.
This method normally shouldn’t be redefined in child classes.
- execute_when_ready(action, *args, check_ready=None)[source]
Acquires device lock, waits till device is ready and runs specified action. If no method is provided for checking,
PyLabware.models.AbstractLabDevice._is_idle()
is used.- Parameters:
action (
Callable
) –- A method to run when the device is ready
args: List of positional arguments for the method to run
check_ready: A method to use for checking whether the device is ready or not. (keyword-only)
check_ready (Callable | None) –
- Returns:
The return value of action.
- Return type:
(any)
- parse_reply(cmd, reply)[source]
This function takes a LabDeviceReply object and does all necessary processing to return a reply string back. Parsing is done according to command specification.
This method may be redefined in child classes.
- Parameters:
reply (
Any
) – Reply from the devicecmd (
Dict
) – Command definition to look the parsing workflow in.
- Returns:
Processed reply
- Return type:
(any)
- prepare_message(cmd, value)[source]
This function does all preparations needed to make the command compliant with device protocol, e.g. type casts the parameters, checks that their values are in range, adds termination sequences, etc.
This method may be redefined in child classes.
- Parameters:
cmd (
Dict
) – Device command definition.value (
Any
) – Command parameter to set, if any.
- Returns:
Checked & prepared command string.
- Return type:
(str)
- send(cmd, value=None)[source]
This method takes the command to be sent and runs all necessary checks on the command parameter if present and required. Then the command get wrapped with the necessary prefix/terminator and connection lock is acquired. The command string is sent to the device using appropriate connection adapter and _recv() is invoked if a reply is expected. Only after that the connection lock is released.
This method normally shouldn’t be redefined in child classes.
- Parameters:
cmd – The command to send.
value – Command parameter, if any.
- property simulation: bool
Determines whether the device behaves as as a real or simulated one. Simulated device just logs all the commands.
- start_task(interval, method, args=None)[source]
Creates a LabDeviceTask object, starts it and appends the reference to the task instance to the list of tasks.
- Parameters:
interval (
int
) – How often the method should be executed, in secondsmethod (
Callable
) – The function to run.args – Arguments for the function, if any.
- Returns:
Created task object for further reference.
- Return type: