toptica.lasersdk.asyncio.client module
- class toptica.lasersdk.asyncio.client.Client(connection: Connection)
Bases:
objectAn asynchronous client for devices that support the Device Control Protocol (DeCoP).
- Parameters:
connection (Connection) – A connection that is used to communicate with the device.
- async change_ul(ul: UserLevel, password: str | None = None) UserLevel
Changes the user level of the client connection.
- Parameters:
ul (UserLevel) – The requested user level.
password (str | None) – The password for the requested user level.
- Returns:
The new user level or the previous one if the password was incorrect.
- Return type:
- Raises:
UnavailableError – If the connection is closed.
- async close() None
Closes the connection to the device.
- property command_line_available: bool
True if the command line is available, False otherwise.
- Type:
bool
- property connection: Connection
The connection of the client to the device.
- Type:
- async exec(name: str, *args: bool | int | float | str | bytes | bytearray | tuple[Any, ...], input_stream: str | bytes | None = None, output_type: type[str | bytes] | None = None, return_type: type[bool | int | float | str | bytes | bytearray | tuple[Any, ...]] | None = None) bool | int | float | str | bytes | bytearray | tuple[Any, ...] | None
Execute a DeCoP command.
- Parameters:
name (str) – The name of the command.
*args – The parameters of the command.
input_stream (DecopStreamType) – The input stream data of the command.
output_type (DecopStreamMetaType) – The type of the output stream of the command.
return_type (DecopMetaType) – The type of the optional return value.
- Returns:
Either the output stream, the return value or a tuple of both.
- Return type:
DecopType | None
- Raises:
UnavailableError – If the connection is closed or the command line is not available.
DecopError – If the device returned an error when executing the command.
- async get(param_name: str, *param_types: type[bool | int | float | str | bytes | bytearray | tuple[Any, ...]]) bool | int | float | str | bytes | bytearray | tuple[Any, ...]
Returns the current value of a DeCoP parameter.
- Parameters:
param_name (str) – The name of the DeCoP parameter (e.g. ‘laser1:enabled’).
param_types (DecopMetaType) – Zero or more types of the DeCoP parameter.
- Returns:
The current value of the parameter.
- Return type:
DecopType
- Raises:
UnavailableError – If the connection is closed or the command line is not available.
DecopValueError – If the provided types don’t match the result from the device.
- async get_set_value(param_name: str, *param_types: type[bool | int | float | str | bytes | bytearray | tuple[Any, ...]]) bool | int | float | str | bytes | bytearray | tuple[Any, ...]
Returns the current ‘set value’ of a DeCoP parameter.
- Parameters:
param_name (str) – The name of the DeCoP parameter (e.g. ‘laser1:enabled’).
param_types (DecopMetaType) – Zero or more types of the DeCoP parameter.
- Returns:
The ‘set value’ of the parameter.
- Return type:
DecopType
- Raises:
UnavailableError – If the connection is closed or the command line is not available.
DecopValueError – If the provided types don’t match the result from the device.
- property is_open: bool
True if the client connection is open, False otherwise.
- Type:
bool
- property monitoring_line_available: bool
True if the monitoring line is available, False otherwise.
- Type:
bool
- async open() None
Opens a connection to the device.
- Raises:
DeviceNotFoundError – If opening the connection to the device has failed.
- async set(param_name: str, *param_values: bool | int | float | str | bytes | bytearray | tuple[Any, ...]) int
Set a new value for a DeCoP parameter.
- Parameters:
param_name (str) – The name of the DeCoP parameter (e.g. ‘laser1:enabled’).
param_values (DecopType) – One or more parameter values.
- Returns:
Zero if successful or a positive integer indicating a warning.
- Return type:
int
- Raises:
UnavailableError – If the connection is closed or the command line is not available.
DecopError – If the device returned an error when setting the new value.
- async subscribe(param_name: str, param_type: type[bool | int | float | str | bytes | bytearray | tuple[Any, ...]] | None = None, interval: int | None = None, threshold: bool | int | float | str | bytes | bytearray | tuple[Any, ...] | None = None) Subscription
Creates a subscription to the value changes of a parameter.
- Parameters:
param_name (str) – The name of the parameter.
param_type (DecopMetaType | None) – The expected type of the parameter.
interval (int | None) – The minimum update interval (in milliseconds).
threshold (DecopType | None) – The minimum change of the value for an update.
- Returns:
A subscription to the value changes of the parameter.
- Return type:
- Raises:
UnavailableError – If the connection is closed or the monitoring line is not available.
- async unsubscribe(subscription: Subscription) None
Cancels a subscription to the value changes of a parameter.
- Parameters:
subscription (Subscription) – The subscription to cancel.
- Raises:
UnavailableError – If the connection is closed or the monitoring line is not available.
- class toptica.lasersdk.asyncio.client.Subscription(client: Client, name: str)
Bases:
objectA subscription to the value changes of a parameter.
- Parameters:
client (Client) – A client that is used to access the parameter.
name (str) – The name of the parameter (e.g. ‘laser1:amp:ontime’).
- async cancel() None
Cancels the subscription for parameter updates.
- property client: Client | None
The Client of this subscription (maybe None when it was canceled).
- Type:
Client | None
- property name: str
The name of the parameter for this subscription.
- Type:
str
- async next() tuple[datetime, bool | int | float | str | bytes | bytearray | tuple[Any, ...]]
Returns the next value of the subscribed parameter.
- Returns:
- A tuple containing a timestamp and the next available value of
the subscribed parameter.
- Return type:
tuple[Timestamp, DecopType]
- Raises:
DecopError – If the subscription has been cancelled or the monitoring line returned an error message.
- async update(timestamp: datetime, value: SubscriptionValue) None
Updates the subscription with a new value or error.
- Parameters:
timestamp (Timestamp) – The timestamp of the parameter update.
value (SubscriptionValue) – The new value of the parameter or an error.