toptica.lasersdk.asyncio package

Subpackages

Submodules

toptica.lasersdk.asyncio.client module

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

Bases: object

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

UnavailableError – If the connection is closed.

async close() None[source]

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:

Connection

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

async 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:
  • 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 | 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:
  • 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[source]

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 | tuple) int[source]

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 | tuple] | None = None) Subscription[source]

Creates a subscription to the value changes of a parameter.

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

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

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

Raises:

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

async unsubscribe(subscription: Subscription) None[source]

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.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.asyncio.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’).

async 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

async subscribe() Subscription[source]

Creates a subscription to the value changes of the parameter.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

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

Bases: object

A read-only boolean 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’).

async 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

async subscribe() Subscription[source]

Creates a subscription to the value changes of the parameter.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

exception toptica.lasersdk.asyncio.client.DecopError[source]

Bases: Exception

A generic DeCoP error.

class toptica.lasersdk.asyncio.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’).

async 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

async subscribe() Subscription[source]

Creates a subscription to the value changes of the parameter.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.asyncio.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’).

async 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

async subscribe() Subscription[source]

Creates a subscription to the value changes of the parameter.

Returns:

A subscription to updates of the parameter.

Return type:

Subscription

class toptica.lasersdk.asyncio.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’).

async 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

async subscribe() Subscription[source]

Creates a subscription to the value changes of the parameter.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

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

Bases: DecopError

A DeCoP value conversion error.

exception toptica.lasersdk.asyncio.client.DeviceNotFoundError[source]

Bases: DecopError

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

class toptica.lasersdk.asyncio.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’).

async 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

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

async subscribe() Subscription[source]

Creates a subscription to the value changes of the parameter.

Returns:

A subscription to updates of the parameter.

Return type:

Subscription

class toptica.lasersdk.asyncio.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’).

async 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

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

async subscribe() Subscription[source]

Creates a subscription to the value changes of the parameter.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.asyncio.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’).

async 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

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

async subscribe() Subscription[source]

Creates a subscription to the value changes of the parameter.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.asyncio.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’).

async 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

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

async subscribe() Subscription[source]

Creates a subscription to the value changes of the parameter.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.asyncio.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’).

async 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

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

async subscribe() Subscription[source]

Creates a subscription to the value changes of the parameter.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.asyncio.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.asyncio.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.asyncio.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’)

async get() bytes[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

bytes

async 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

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

async subscribe() Subscription[source]

Creates a subscription to the value changes of the parameter.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.asyncio.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’).

async get() bool[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

bool

async 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

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

async subscribe() Subscription[source]

Creates a subscription to the value changes of the parameter.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.asyncio.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’).

async get() int[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

int

async 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

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

async subscribe() Subscription[source]

Creates a subscription to the value changes of the parameter.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.asyncio.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’).

async get() float[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

float

async 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

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

async subscribe() Subscription[source]

Creates a subscription to the value changes of the parameter.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.asyncio.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’).

async get() str[source]

Returns the current value of the parameter.

Returns:

The current value of the parameter.

Return type:

str

async 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

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

async subscribe() Subscription[source]

Creates a subscription to the value changes of the parameter.

Returns:

A subscription to the value changes of the parameter.

Return type:

Subscription

class toptica.lasersdk.asyncio.client.Subscription(client: Client, name: str)[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 name of the parameter (e.g. ‘laser1:amp:ontime’).

async 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

async next() Tuple[datetime, bool | int | float | str | bytes | tuple][source]

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[source]

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.

class toptica.lasersdk.asyncio.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.asyncio.client.Timestamp

alias of datetime

class toptica.lasersdk.asyncio.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.asyncio.connection module

exception toptica.lasersdk.asyncio.connection.BufferOverflowError[source]

Bases: DecopError

An exception that is raised when the amount of received data exceeds the size of the internal buffer.

class toptica.lasersdk.asyncio.connection.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.

exception toptica.lasersdk.asyncio.connection.ConnectionClosedError[source]

Bases: DecopError

An exception that is raised when a connection is closed.

exception toptica.lasersdk.asyncio.connection.DecopError[source]

Bases: Exception

A generic DeCoP error.

exception toptica.lasersdk.asyncio.connection.DeviceNotFoundError[source]

Bases: DecopError

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

class toptica.lasersdk.asyncio.connection.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.asyncio.connection.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.

exception toptica.lasersdk.asyncio.connection.UnavailableError[source]

Bases: DecopError

An exception that is raised when a command line or monitoring line is used that is not available.

Module contents