toptica.lasersdk.asyncio.connection module
- exception toptica.lasersdk.asyncio.connection.BufferOverflowError
Bases:
DecopErrorAn exception that is raised when the amount of received data exceeds the size of the internal buffer.
- class toptica.lasersdk.asyncio.connection.Connection
Bases:
ABCAn abstract base class for connection objects.
- abstractmethod async close() None
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
- abstractmethod async open() None
Opens the connection to a device.
- abstractmethod async read_command_line() str
Reads a message from the command line of the device.
- abstractmethod async read_monitoring_line() str
Reads a message from the monitoring line of the device.
- abstract property timeout: float
The timeout value (in seconds) of the connection.
- Type:
float
- abstractmethod async write_command_line(message: str) None
Writes a message to the monitoring line of the device.
- abstractmethod async write_monitoring_line(message: str) None
Writes a message to the monitoring line of the device.
- exception toptica.lasersdk.asyncio.connection.ConnectionClosedError
Bases:
DecopErrorAn exception that is raised when a connection is closed.
- exception toptica.lasersdk.asyncio.connection.DeviceNotFoundError
Bases:
DecopErrorAn exception that is raised when connecting to a device has failed.
- class toptica.lasersdk.asyncio.connection.DiscoveryProtocol(device_name: str)
Bases:
DatagramProtocolAn implementation of a DatagramProtocol for device discovery.
- Parameters:
device_name (str) – The serial number or system label of the device.
- connection_made(transport: BaseTransport) None
Called when a connection is made.
The argument is the transport representing the pipe connection. To receive data, wait for data_received() calls. When the connection is closed, connection_lost() is called.
- datagram_received(data: bytes, addr: tuple[str, int]) None
Called when some datagram is received.
- error_received(exc: Exception) None
Called when a send or receive operation raises an OSError.
(Other than BlockingIOError or InterruptedError.)
- property result: Future[tuple[IPv4Address | IPv6Address, int, int]]
The result of the discovery process.
- Type:
asyncio.Future[DeviceNetworkAddress]
- class toptica.lasersdk.asyncio.connection.NetworkConnection(host: str, command_line_port: int = 1998, monitoring_line_port: int = 1999, timeout: float = 5)
Bases:
ConnectionA 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
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
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:
DeviceNetworkAddress | None
- 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
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
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
Reads a message from the monitoring line of the device.
- Returns:
The message read from the monitoring line.
- Return type:
str
- Raises:
UnavailableError – If the monitoring line is not available.
BufferOverflowError – If the received data overflowed the internal buffer.
- property timeout: float
The timeout value (in seconds) of the connection.
- Type:
float
- async write_command_line(message: str) None
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
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)
Bases:
ConnectionA serial connection to a device.
- Parameters:
port (str) – The name of a serial port (e.g. ‘COM1’ or ‘/dev/ttyUSB0’) or a pyserial URL handler (https://pyserial.readthedocs.io/en/latest/url_handlers.html).
baudrate (int) – The number of transferred bits per second.
timeout (float) – The communication timeout (in seconds).
- async close() None
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
Opens a serial connection to the device.
- Raises:
DeviceNotFoundError – If connecting to the device failed.
- async read_command_line() str
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
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
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
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.
Bases:
DecopErrorAn exception that is raised when a command line or monitoring line is used that is not available.