toptica.lasersdk package

Subpackages

Submodules

toptica.lasersdk.client module

class toptica.lasersdk.client.Client(connection: Connection)[source]

Bases: object

A client for devices that support the Device Control Protocol (DeCoP).

Parameters:

connection (Connection) – A connection that is used to communicate with the device.

change_ul(ul: UserLevel, password: str | None = None) UserLevel[source]

Changes the user level of the client connection.

Parameters:
  • ul (UserLevel) – The requested user level.

  • password (Optional[str]) – The password for the requested user level.

Returns:

The new user level or the previous one if the password was incorrect.

Return type:

UserLevel

Raises:
close() None[source]

Closes the connection to the device.

Raises:

DeviceTimeoutError – If the operation did not complete in time.

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:

Connection

exec(name: str, *args, input_stream: str | bytes | None = None, output_type: Type[str | bytes] | None = None, return_type: Type[bool | int | float | str | bytes | tuple] | None = None) bool | int | float | str | bytes | tuple | None[source]

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:

Optional[DecopType]

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.

  • DeviceTimeoutError – If the operation did not complete in time.

get(param_name: str, *param_types: Type[bool | int | float | str | bytes | tuple]) bool | int | float | str | bytes | tuple[source]

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:
get_set_value(param_name: str, *param_types: Type[bool | int | float | str | bytes | tuple]) bool | int | float | str | bytes | tuple[source]

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:
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

open() None[source]

Opens a connection to the device.

Raises:

DeviceNotFoundError – If opening the connection to the device has failed.

poll() None[source]

Invokes the next queued callback.

Raises:

UnavailableError – If the connection is closed or the monitoring line is not available.

run(timeout: float | None = None) None[source]

Invokes all scheduled callbacks until a timeout occurres.

Parameters:

timeout (Optional[float]) – An optional timeout (in seconds) after this function will return. Without a timeout this function will run indefinitely (or until stop() is called). When timeout=0 this function behaves like poll().

Raises:

UnavailableError – If the connection is closed or the monitoring line is not available.

set(param_name: str, *param_values: bool | int | float | str | bytes | tuple) int[source]

Sets 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.

  • DeviceTimeoutError – If the operation did not complete in time.

stop() None[source]

Stops the event loop for the monitoring line.

subscribe(param_name: str, callback: Callable[[Subscription, datetime, SubscriptionValue], None], param_type: Type[bool | int | float | str | bytes | tuple] | None = None) Subscription[source]

Creates a subscription to the value changes of a parameter.

Parameters:
  • param_name (str) – The name of the parameter.

  • callback (DecopCallback) – The callback that will be invoked on parameter updates.

  • param_type (Optional[DecopMetaType]) – The expected type of the parameter.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

Raises:
unsubscribe(subscription: Subscription) None[source]

Cancels a subscription to the value changes of a parameter.

Parameters:

subscription (Subscription) – The subscription to cancel.

Raises:
class toptica.lasersdk.client.Connection[source]

Bases: ABC

An abstract base class for connection objects.

abstract async close() None[source]

Closes the connection to a device.

abstract property command_line_available: bool

True if the command line is available, False otherwise.

Type:

bool

abstract property is_open: bool

True if the connection is open, False otherwise.

Type:

bool

abstract property loop: AbstractEventLoop

The event loop used by the connection.

Type:

AbstractEventLoop

abstract property monitoring_line_available: bool

True if the monitoring line is available, False otherwise.

Type:

bool

abstract async open() None[source]

Opens the connection to a device.

abstract async read_command_line() str[source]

Reads a message from the command line of the device.

abstract async read_monitoring_line() str[source]

Reads a message from the monitoring line of the device.

abstract property timeout: float

The timeout value (in seconds) of the connection.

Type:

float

abstract async write_command_line(message: str) None[source]

Writes a message to the monitoring line of the device.

abstract async write_monitoring_line(message: str) None[source]

Writes a message to the monitoring line of the device.

class toptica.lasersdk.client.DecopBinary(client: Client, name: str)[source]

Bases: object

A read-only DeCoP binary parameter.

Parameters:
  • client (Client) – A DeCoP client that is used to access the parameter on a device.

  • name (str) – The fully qualified name of the parameter (e.g. ‘laser1:amp:ontime’).

get() bytes[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

bytes

property name: str

The fully qualified name of the parameter.

Type:

str

subscribe(callback: Callable[[Subscription, datetime, SubscriptionValue], None]) Subscription[source]

Creates a subscription to the value changes of the parameter.

Parameters:

callback (DecopCallback) – A callback that will be invoked when the value of the parameter has changed.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.client.DecopBoolean(client: Client, name: str)[source]

Bases: object

A read-only DeCoP boolean parameter.

Parameters:
  • client (Client) – A DeCoP client that is used to access the parameter on a device.

  • name (str) – The fully qualified name of the parameter (e.g. ‘laser1:amp:ontime’).

get() bool[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

bool

property name: str

The fully qualified name of the parameter.

Type:

str

subscribe(callback: Callable[[Subscription, datetime, SubscriptionValue], None]) Subscription[source]

Creates a subscription to the value changes of the parameter.

Parameters:

callback (DecopCallback) – A callback that will be invoked when the value of the parameter has changed.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

exception toptica.lasersdk.client.DecopError[source]

Bases: Exception

A generic DeCoP error.

class toptica.lasersdk.client.DecopInteger(client: Client, name: str)[source]

Bases: object

A read-only DeCoP integer parameter.

Parameters:
  • client (Client) – A DeCoP client that is used to access the parameter on a device.

  • name (str) – The fully qualified name of the parameter (e.g. ‘laser1:amp:ontime’).

get() int[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

int

property name: str

The fully qualified name of the parameter.

Type:

str

subscribe(callback: Callable[[Subscription, datetime, SubscriptionValue], None]) Subscription[source]

Creates a subscription to the value changes of the parameter.

Parameters:

callback (DecopCallback) – A callback that will be invoked when the value of the parameter has changed.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.client.DecopReal(client: Client, name: str)[source]

Bases: object

A read-only DeCoP floating point parameter.

Parameters:
  • client (Client) – A DeCoP client that is used to access the parameter on a device.

  • name (str) – The fully qualified name of the parameter (e.g. ‘laser1:amp:ontime’).

get() float[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

float

property name: str

The fully qualified name of the parameter.

Type:

str

subscribe(callback: Callable[[Subscription, datetime, SubscriptionValue], None]) Subscription[source]

Creates a subscription to the value changes of the parameter.

Parameters:

callback (DecopCallback) – A callback that will be invoked when the value of the parameter has changed.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.client.DecopString(client: Client, name: str)[source]

Bases: object

A read-only DeCoP string parameter.

Parameters:
  • client (Client) – A DeCoP client that is used to access the parameter on a device.

  • name (str) – The fully qualified name of the parameter (e.g. ‘laser1:amp:ontime’).

get() str[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

str

property name: str

The fully qualified name of the parameter.

Type:

str

subscribe(callback: Callable[[Subscription, datetime, SubscriptionValue], None]) Subscription[source]

Creates a subscription to the value changes of the parameter.

Parameters:

callback (DecopCallback) – A callback that will be invoked when the value of the parameter has changed.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

exception toptica.lasersdk.client.DecopValueError(value: str, expected_type: type | None = None)[source]

Bases: DecopError

A DeCoP value conversion error.

exception toptica.lasersdk.client.DeviceNotFoundError[source]

Bases: DecopError

An exception that is raised when connecting to a device has failed.

exception toptica.lasersdk.client.DeviceTimeoutError[source]

Bases: DecopError

An exception that is raised when connecting to a device has failed.

class toptica.lasersdk.client.MutableDecopBinary(client: Client, name: str)[source]

Bases: object

A read/write DeCoP binary parameter.

Parameters:
  • client (Client) – A DeCoP client that is used to access the parameter on a device.

  • name (str) – The fully qualified name of the parameter (e.g. ‘laser1:amp:ontime’).

get() bytes[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

bytes

property name: str

The fully qualified name of the parameter.

Type:

str

set(value: bytes | bytearray) int[source]

Updates the value of the parameter.

Parameters:

value (Union[bytes, bytearray]) – The new value of the parameter.

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.

subscribe(callback: Callable[[Subscription, datetime, SubscriptionValue], None]) Subscription[source]

Creates a subscription to the value changes of the parameter.

Parameters:

callback (DecopCallback) – A callback that will be invoked when the value of the parameter has changed.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.client.MutableDecopBoolean(client: Client, name: str)[source]

Bases: object

A read/write DeCoP boolean parameter.

Parameters:
  • client (Client) – A DeCoP client that is used to access the parameter on a device.

  • name (str) – The fully qualified name of the parameter (e.g. ‘laser1:amp:ontime’).

get() bool[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

bool

property name: str

The fully qualified name of the parameter.

Type:

str

set(value: bool) int[source]

Updates the value of the parameter.

Parameters:

value (bool) – The new value of the parameter.

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.

subscribe(callback: Callable[[Subscription, datetime, SubscriptionValue], None]) Subscription[source]

Creates a subscription to the value changes of the parameter.

Parameters:

callback (DecopCallback) – A callback that will be invoked when the value of the parameter has changed.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.client.MutableDecopInteger(client: Client, name: str)[source]

Bases: object

A read/write DeCoP integer parameter.

Parameters:
  • client (Client) – A DeCoP client that is used to access the parameter on a device.

  • name (str) – The fully qualified name of the parameter (e.g. ‘laser1:amp:ontime’).

get() int[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

int

property name: str

The fully qualified name of the parameter.

Type:

str

set(value: int) int[source]

Updates the value of the parameter.

Parameters:

value (int) – The new value of the parameter.

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.

subscribe(callback: Callable[[Subscription, datetime, SubscriptionValue], None]) Subscription[source]

Creates a subscription to the value changes of the parameter.

Parameters:

callback (DecopCallback) – A callback that will be invoked when the value of the parameter has changed.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.client.MutableDecopReal(client: Client, name: str)[source]

Bases: object

A read/write DeCoP floating point parameter.

Parameters:
  • client (Client) – A DeCoP client that is used to access the parameter on a device.

  • name (str) – The fully qualified name of the parameter (e.g. ‘laser1:amp:ontime’).

get() float[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

float

property name: str

The fully qualified name of the parameter.

Type:

str

set(value: int | float) int[source]

Updates the value of the parameter.

Parameters:
  • Union[int (value) – The new value of the parameter.

  • float] – The new value of the parameter.

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.

subscribe(callback: Callable[[Subscription, datetime, SubscriptionValue], None]) Subscription[source]

Creates a subscription to the value changes of the parameter.

Parameters:

callback (DecopCallback) – A callback that will be invoked when the value of the parameter has changed.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.client.MutableDecopString(client: Client, name: str)[source]

Bases: object

A read/write DeCoP string parameter.

Parameters:
  • client (Client) – A DeCoP client that is used to access the parameter on a device.

  • name (str) – The fully qualified name of the parameter (e.g. ‘laser1:amp:ontime’).

get() str[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

str

property name: str

The fully qualified name of the parameter.

Type:

str

set(value: str) int[source]

Updates the value of the parameter.

Parameters:

value (str) – The new value of the parameter.

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.

subscribe(callback: Callable[[Subscription, datetime, SubscriptionValue], None]) Subscription[source]

Creates a subscription to the value changes of the parameter.

Parameters:

callback (DecopCallback) – A callback that will be invoked when the value of the parameter has changed.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.client.NetworkConnection(host: str, command_line_port: int = 1998, monitoring_line_port: int = 1999, timeout: float = 5)[source]

Bases: Connection

A network connection to a device.

Parameters:
  • host (str) – The IP address, DNS hostname, serial number or system label of the device.

  • command_line_port (int) – The TCP port of the command line (can be 0 if the command line is not required or supported by the device).

  • monitoring_line_port (int) – The TCP port of the monitoring line (can be 0 if the monitoring line is not required or supported by the device).

  • timeout (float) – The timeout (in seconds) of this connection.

async close() None[source]

Closes the network connection.

property command_line_available: bool

True if the command line is available, False otherwise.

Type:

bool

async static find_device(name: str, timeout: float = 5) Tuple[IPv4Address | IPv6Address, int, int] | None[source]

Tries to find a device in the local network using its serial number or system label.

Parameters:
  • name (str) – The serial number or system label of the device.

  • timeout (int) – The timeout for waiting for a response from the searched device.

Returns:

A tuple containing the IP address and TCP ports of the device

or None if the device could not be found.

Return type:

Optional[DeviceNetworkAddress]

property is_open: bool

True if the connection is open, False otherwise.

Type:

bool

property loop: AbstractEventLoop

The event loop used by the connection.

Type:

AbstractEventLoop

property monitoring_line_available: bool

True if the monitoring line is available, False otherwise.

Type:

bool

async open() None[source]

Opens a network connection to the device.

Raises:

DeviceNotFoundError – If an invalid IP address was provided or no IP address could be found for the DNS hostname, serial number or system label.

async read_command_line() str[source]

Reads a message from the command line of the device.

Returns:

The message read from the command line.

Return type:

str

Raises:
  • BufferOverflowError – If the amount of received data exceeds the size of the internal buffer.

  • ConnectionClosedError – If the connection was closed either by calling close() or due to a network error.

async read_monitoring_line() str[source]

Reads a message from the monitoring line of the device.

Returns:

The message read from the monitoring line.

Return type:

str

Raises:
property timeout: float

The timeout value (in seconds) of the connection.

Type:

float

async write_command_line(message: str) None[source]

Sends a message to the command line.

Parameters:

message (str) – The message to send to the command line.

Raises:

UnavailableError – If the connection is either closed or the command line is not available.

async write_monitoring_line(message: str) None[source]

Sends a message to the monitoring line.

Parameters:

message (str) – The message to send to the monitoring line.

Raises:
  • BufferOverflowError – If the amount of received data exceeds the size of the internal buffer.

  • ConnectionClosedError – If the connection was closed either by calling close() or due to a network error.

class toptica.lasersdk.client.SerialConnection(port: str, baudrate: int = 115200, timeout: float = 5)[source]

Bases: Connection

A serial connection to a device.

Parameters:
async close() None[source]

Closes the serial connection to the device.

property command_line_available: bool

True if the command line is available, False otherwise.

Type:

bool

property is_open: bool

True if the connection is open, False otherwise.

Type:

bool

property loop: AbstractEventLoop

The event loop used by the connection.

Type:

AbstractEventLoop

property monitoring_line_available: bool

Always False because the monitoring line is not available on serial connections.

Type:

bool

async open() None[source]

Opens a serial connection to the device.

Raises:

DeviceNotFoundError – If connecting to the device failed.

async read_command_line() str[source]

Reads a message from the command line of the device.

Returns:

The message read from the command line.

Return type:

str

Raises:

UnavailableError – If the connection is closed.

async read_monitoring_line() str[source]

Reads a message from the monitoring line of the device.

The monitoring line is not available on serial connections, therefore this method will always raise an UnavailableError.

Returns:

The message read from the monitoring line.

Return type:

str

Raises:

UnavailableError – Always because the monitoring line is not available on serial connections.

property timeout: float

The timeout value (in seconds) of the connection.

Type:

float

async write_command_line(message: str) None[source]

Sends a message to the command line.

Parameters:

message (str) – The message to send to the command line.

Raises:

UnavailableError – If the connection is closed.

async write_monitoring_line(message: str) None[source]

Sends a message to the monitoring line of the device.

The monitoring line is not available on serial connections, therefore this method will always raise an UnavailableError.

Parameters:

message (str) – The message to send to the monitoring line.

Raises:

UnavailableError – Always because the monitoring line is not available on serial connections.

class toptica.lasersdk.client.SettableDecopBinary(client: Client, name: str)[source]

Bases: object

A settable DeCoP binary parameter.

Parameters:
  • client (Client) – A DeCoP client that is used to access the parameter on a device.

  • name (str) – The fully qualified name of the parameter (e.g. ‘laser1:amp:ontime’).

get() bytes[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

bytes

get_set_value() bytes[source]

Returns the current set-value of the parameter.

Returns:

The current set-value of the parameter.

Return type:

bytes

property name: str

The fully qualified name of the parameter.

Type:

str

set(value: bytes | bytearray) int[source]

Updates the value of the parameter.

Parameters:

value (Union[bytes, bytearray]) – The new value of the parameter.

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.

subscribe(callback: Callable[[Subscription, datetime, SubscriptionValue], None]) Subscription[source]

Creates a subscription to the value changes of the parameter.

Parameters:

callback (DecopCallback) – A callback that will be invoked when the value of the parameter has changed.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.client.SettableDecopBoolean(client: Client, name: str)[source]

Bases: object

A settable DeCoP boolean parameter.

Parameters:
  • client (Client) – A DeCoP client that is used to access the parameter on a device.

  • name (str) – The fully qualified name of the parameter (e.g. ‘laser1:amp:ontime’).

get() bool[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

bool

get_set_value() bool[source]

Returns the current set-value of the parameter.

Returns:

The current set-value of the parameter.

Return type:

bool

property name: str

The fully qualified name of the parameter.

Type:

str

set(value: bool) int[source]

Updates the value of the parameter.

Parameters:

value (bool) – The new value of the parameter.

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.

subscribe(callback: Callable[[Subscription, datetime, SubscriptionValue], None]) Subscription[source]

Creates a subscription to the value changes of the parameter.

Parameters:

callback (DecopCallback) – A callback that will be invoked when the value of the parameter has changed.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.client.SettableDecopInteger(client: Client, name: str)[source]

Bases: object

A settable DeCoP integer parameter.

Parameters:
  • client (Client) – A DeCoP client that is used to access the parameter on a device.

  • name (str) – The fully qualified name of the parameter (e.g. ‘laser1:amp:ontime’).

get() int[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

int

get_set_value() int[source]

Returns the current set-value of the parameter.

Returns:

The current set-value of the parameter.

Return type:

int

property name: str

The fully qualified name of the parameter.

Type:

str

set(value: int) int[source]

Updates the value of the parameter.

Parameters:

value (int) – The new value of the parameter.

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.

subscribe(callback: Callable[[Subscription, datetime, SubscriptionValue], None]) Subscription[source]

Creates a subscription to the value changes of the parameter.

Parameters:

callback (DecopCallback) – A callback that will be invoked when the value of the parameter has changed.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.client.SettableDecopReal(client: Client, name: str)[source]

Bases: object

A settable DeCoP floating point parameter.

Parameters:
  • client (Client) – A DeCoP client that is used to access the parameter on a device.

  • name (str) – The fully qualified name of the parameter (e.g. ‘laser1:amp:ontime’).

get() float[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

float

get_set_value() float[source]

Returns the current set-value of the parameter.

Returns:

The current set-value of the parameter.

Return type:

float

property name: str

The fully qualified name of the parameter.

Type:

str

set(value: int | float) int[source]

Updates the value of the parameter.

Parameters:
  • Union[int (value) – The new value of the parameter.

  • float] – The new value of the parameter.

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.

subscribe(callback: Callable[[Subscription, datetime, SubscriptionValue], None]) Subscription[source]

Creates a subscription to the value changes of the parameter.

Parameters:

callback (DecopCallback) – A callback that will be invoked when the value of the parameter has changed.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.client.SettableDecopString(client: Client, name: str)[source]

Bases: object

A settable DeCoP string parameter.

Parameters:
  • client (Client) – A DeCoP client that is used to access the parameter on a device.

  • name (str) – The fully qualified name of the parameter (e.g. ‘laser1:amp:ontime’).

get() str[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

str

get_set_value() str[source]

Returns the current set-value of the parameter.

Returns:

The current set-value of the parameter.

Return type:

str

property name: str

The fully qualified name of the parameter.

Type:

str

set(value: str) int[source]

Updates the value of the parameter.

Parameters:

value (str) – The new value of the parameter.

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.

subscribe(callback: Callable[[Subscription, datetime, SubscriptionValue], None]) Subscription[source]

Creates a subscription to the value changes of the parameter.

Parameters:

callback (DecopCallback) – A callback that will be invoked when the value of the parameter has changed.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.client.Subscription(client: Client, name: str, callback: Callable[[Subscription, datetime, SubscriptionValue], None])[source]

Bases: object

A subscription to the value changes of a parameter.

Parameters:
  • client (Client) – A client that is used to access the parameter.

  • name (str) – The fully qualified name of the parameter (e.g. ‘laser1:amp:ontime’).

  • callback (DecopCallback) – A callback that will be invoked when the value of the parameter has changed.

cancel() None[source]

Cancels the subscription for parameter updates.

property client: Client | None

The Client of this subscription (maybe None when it was canceled).

Type:

Optional[Client]

property name: str

The name of the parameter for this subscription.

Type:

str

update(timestamp: datetime, value: SubscriptionValue) None[source]

Invokes the callback with an updated parameter value.

Parameters:
  • timestamp (Timestamp) – The timestamp of the parameter update.

  • value (SubscriptionValue) – The new value of the parameter or an error.

class toptica.lasersdk.client.SubscriptionValue(value: bool | int | float | str | bytes | tuple | DecopError)[source]

Bases: object

Wrapper type for either the value of a subscription or any exception that may have been raised.

Parameters:

value (Union[DecopType, DecopError]) – The value from the subscription or an exception that may have occurred.

get() bool | int | float | str | bytes | tuple[source]

Returns the value from the subscription or re-raises any exception that may have occurred.

Returns:

The value from the subscription.

Return type:

DecopType

Raises:

DecopError – The exception that has been raised while handling the subscription value.

property value: bool | int | float | str | bytes | tuple | DecopError

The value or exception of a subscription.

Type:

Union[DecopType, DecopError]

toptica.lasersdk.client.Timestamp

alias of datetime

class toptica.lasersdk.client.UserLevel(value)[source]

Bases: IntEnum

A user level of a parameter in a DeCoP system model.

INTERNAL = 0
MAINTENANCE = 2
NORMAL = 3
READONLY = 4
SERVICE = 1

toptica.lasersdk.decop module

class toptica.lasersdk.decop.Command(name: str, description: str, input_type: StreamType | None, output_type: StreamType | None, execlevel: UserLevel | None, params: List[Tuple[str, str]], return_type: str | None)[source]

Bases: object

A command in the DeCoP system model.

Parameters:
  • name (str) – The name of the command.

  • input_type (StreamType) – The type of the input stream.

  • output_type (StreamType) – The type of the output stream.

  • execlevel (UserLevel) – The required user level to execute the command.

  • params (List[Tuple[str, str]]) – The list of parameter names and types of the command.

  • return_type (str) – The type of the return value.

exception toptica.lasersdk.decop.DecopError[source]

Bases: Exception

A generic DeCoP error.

exception toptica.lasersdk.decop.DecopValueError(value: str, expected_type: type | None = None)[source]

Bases: DecopError

A DeCoP value conversion error.

class toptica.lasersdk.decop.Module(name: str)[source]

Bases: object

A module in a DeCoP system model.

name

The name of the module.

Type:

str

class toptica.lasersdk.decop.ParamMode(value)[source]

Bases: Enum

An access mode of a parameter in a DeCoP system model.

READONLY = 1
READSET = 4
READWRITE = 3
WRITEONLY = 2
class toptica.lasersdk.decop.Parameter(name: str, typestr: str, description: str, mode: ParamMode | None, readlevel: UserLevel | None, writelevel: UserLevel | None)[source]

Bases: object

A parameter in a DeCoP system model.

Parameters:
  • name (str) – The name of the parameter.

  • typestr (str) – The type of the parameter.

  • mode (ParamMode) – The access mode of the parameter.

  • readlevel (UserLevel) – The required user level to read the parameter.

  • writelevel (UserLevel) – The required user level to write the parameter.

class toptica.lasersdk.decop.StreamType(value)[source]

Bases: Enum

A stream-type of a command in a DeCoP system model.

BASE64 = 2
TEXT = 1
class toptica.lasersdk.decop.SubscriptionValue(value: bool | int | float | str | bytes | tuple | DecopError)[source]

Bases: object

Wrapper type for either the value of a subscription or any exception that may have been raised.

Parameters:

value (Union[DecopType, DecopError]) – The value from the subscription or an exception that may have occurred.

get() bool | int | float | str | bytes | tuple[source]

Returns the value from the subscription or re-raises any exception that may have occurred.

Returns:

The value from the subscription.

Return type:

DecopType

Raises:

DecopError – The exception that has been raised while handling the subscription value.

property value: bool | int | float | str | bytes | tuple | DecopError

The value or exception of a subscription.

Type:

Union[DecopType, DecopError]

class toptica.lasersdk.decop.SystemModel[source]

Bases: object

A DeCoP system model.

build_from_file(filename: str) None[source]

Loads a DeCoP system model from an XML file.

Parameters:

filename (str) – The name of the XML file with the DeCoP system model.

build_from_string(xml_str: str) None[source]

Loads a DeCoP system model form a string.

Parameters:

xml_str (str) – A string containing the XML description of the DeCoP system model.

class toptica.lasersdk.decop.Typedef(name: str, is_atomic: bool)[source]

Bases: object

A typedef in a DeCoP system model.

Parameters:
  • name (str) – The name of the typedef.

  • is_atomic (bool) – True if the typedef is atomic, False otherwise.

class toptica.lasersdk.decop.UserLevel(value)[source]

Bases: IntEnum

A user level of a parameter in a DeCoP system model.

INTERNAL = 0
MAINTENANCE = 2
NORMAL = 3
READONLY = 4
SERVICE = 1
toptica.lasersdk.decop.access_mode(access_mode_str: str | None) ParamMode | None[source]

Converts a string with a parameter access mode to the corresponding type.

Parameters:

access_mode_str (str) – The string with the parameter access mode.

Returns:

The type of the parameter access mode.

Return type:

Optional[ParamMode]

toptica.lasersdk.decop.decode_value(result: str, expected_type: Type[bool | int | float | str | bytes | tuple]) bool | int | float | str | bytes | tuple[source]

Converts a DeCoP parameter string to a Python value.

Parameters:
  • result (str) – The string returned by the command line.

  • expected_type (DecopTypeList) – The expected type of the result.

Returns:

The value of the command line result.

Return type:

DecopType

Raises:
  • DecopError – If the command line returned an error message

  • DecopValueError – If the command line result couldn’t be converted to the expected type.

toptica.lasersdk.decop.decode_value_inferred(param_str: str) bool | int | float | str | bytes | tuple[source]

Tries to convert a DeCoP parameter string to a Python type by inferring its data type.

Parameters:

param_str (str) – The string containing the parameter value.

Returns:

The value of the parameter string.

Return type:

DecopType

Raises:
  • DecopError – If the parameter string contains an error message.

  • DecopValueError – If the data type of the parameter string couldn’t be inferred.

toptica.lasersdk.decop.encode_value(value: bool | int | float | str | bytes | tuple) str[source]

Encodes a value to a string.

Parameters:

value (DecopType) – The value of the parameter.

Returns:

The encoded value.

Return type:

str

toptica.lasersdk.decop.parse_monitoring_line(line: str) Tuple[datetime, str, str | DecopError][source]

Parses a monitoring line message.

Parameters:

line (str) – A monitoring line message.

Returns:

A tuple containing the timestamp, parameter name and value/exception.

Return type:

DecopMonitoringLine

toptica.lasersdk.decop.stream_type(stream_type_str: str | None) StreamType | None[source]

Converts a string with a command stream type to the corresponding type.

Parameters:

stream_type_str (str) – The string with the command stream type.

Returns:

The type of the command stream type.

Return type:

Optional[StreamType]

toptica.lasersdk.decop.user_level(user_level_str: str | None) UserLevel | None[source]

Converts a string with a parameter user level to the corresponding type.

Parameters:

user_level_str (str) – The string with the parameter user level.

Returns:

The type of the parameter user level.

Return type:

Optional[UserLevel]

Module contents