Device communication#
Discover a device, manage its serial connection, and query or change its state.
All functions are available from the opensync package.
Connections#
- opensync.device_comm_search()#
Search for available serial ports.
This function scans the system for available serial ports and returns a list of devices that are currently connected.
- Returns:
ports – A list of strings representing the names of the connected serial ports.
- Return type:
list[str]
Examples
>>> opensync_port = device_comm_search() >>> print(opensync_port) ['COM3']
- opensync.device_comm_open(port, fast=False)#
Open a connection to a specified serial port.
This function initializes a new OpenSync device connection on the specified serial port with predefined baud rate and timeouts.
- Parameters:
port (str) – The name of the serial port to which the OpenSync device will connect.
fast (bool) – If enabled, decrease the serial response wait time by over half.
- Returns:
device – An instance of the OpenSync device that is connected to the specified port.
- Return type:
‘opensync’
- Raises:
SerialException – If the connection to the specified port cannot be established.
- opensync.device_comm_close(device)#
Close the connection to the OpenSync device.
This function closes the serial connection to the OpenSync device, releasing any resources associated with the connection.
- Parameters:
device ('opensync') – An instance of the OpenSync device that will be closed.
- Return type:
None
- opensync.device_comm_managed(port, fast=False)#
Context manager for managing the OpenSync device connection.
This context manager opens a connection to the specified serial port and ensures that the connection is properly closed when the context is exited.
- Parameters:
port (str) – The name of the serial port to which the OpenSync device will connect.
fast (bool) – If enabled, decrease the serial response wait time by over half.
- Yields:
device (‘opensync’) – An instance of the OpenSync device that is connected to the specified port.
- opensync.device_comm_write(device, command, output=True, eol='\r\n')#
Send a command to the OpenSync device.
This function writes a command to the OpenSync device, appending an end-of-line character, and retrieves the response from the device.
- Parameters:
device ('opensync') – An instance of the OpenSync device to which the command will be sent.
command (str) – The command string to be sent to the device.
output (bool) – Return the retrieved device output if expecting one.
eol (str, optional) – The end-of-line character(s) to append to the command (default is ‘rn’).
- Returns:
response – A list of strings containing the responses from the OpenSync device after executing the command.
- Return type:
list[str]
Device information and operation#
- opensync.device_system_version(device)#
Retrieve the version information from the OpenSync device.
This function sends a command to the OpenSync device to obtain its version information.
- Parameters:
device ('opensync') – An instance of the OpenSync device from which to retrieve the version.
- Returns:
response – A list of strings containing the version information of the device.
- Return type:
list[str]
- opensync.device_system_status(device)#
Retrieve the current status from the OpenSync device.
This function sends a command to the OpenSync device to obtain its current operational status.
- Parameters:
device ('opensync') – An instance of the OpenSync device from which to retrieve the status.
- Returns:
response – A list of strings containing the current status of the device.
- Return type:
list[str]
- opensync.device_system_fire(device)#
Execute a pulse sequence from the OpenSync device buffer.
This function sends a command to the OpenSync device to execute a fire operation for the specified number of repetitions.
- Parameters:
device ('opensync') – An instance of the OpenSync device on which to execute the command.
- Returns:
response – A list of strings containing the response from the device after executing the command.
- Return type:
list[str]
- opensync.device_system_stop(device)#
Stop the current operation of the OpenSync device.
This function sends a command to the OpenSync device to stop its current operation.
- Parameters:
device ('opensync') – An instance of the OpenSync device on which to execute the stop command.
- Returns:
response – A list of strings containing the response from the device after executing the stop command.
- Return type:
list[str]