srsgui.inst.communications package
srsgui.inst.communications.interface module
- class srsgui.inst.communications.interface.Interface
Bases:
object
Base class for communication interfaces to be used in Instrument class. A subclass should implement all the methods in the class
- NAME = 'interface'
- set_callbacks(queried=None, sent=None, recvd=None, connected=None, disconnected=None)
Set callback functions for query_text, send, recv, connect, disconnect operation of the interface. Typically, callback functions are used to log the communication activity.
print
andlogging.debug
is simple callback functions to use.- Parameters:
queried (function(msg:str)) – function called after query_text()
sent (function(msg:str)) – function called after send()
recvd (function(msg:str)) – function called after recv()
connected (function(msg:str)) – function called after connect()
disconnected (function(msg(str)) – function called after disconnect()
- get_lock()
Get the lock to secure exclusive access to the communication interface
- connect(*args, **kwargs)
connect to the communication interface
Subclass will have its own connect arguments
- disconnect()
Disconnect from the communication interface
- is_connected()
check if the communication interface is connected
- Return type:
bool
- static parse_parameter_string(param_string)
Parse a connection parameter string used in .taskconfig file
- set_term_char(ch)
Set termination character for text-based communication
Some instruments use the line-feed character, b’n’ as termination character for the remote commands and the replies, or others use the carriage return character, b’r’.
- Parameters:
ch (bytes) – termination character
- get_term_char()
Get termination character for text-based communication
- Return type:
bytes
- send(cmd)
Send a remote command to the instrument
If the cmd does not have the termination character, it will attach one at the end of the cmd string, and convert the string to a byte array before sending
- Parameters:
cmd (str) – remote command to send
- recv()
Receive a byte array until a termination character and convert to a string
- Returns:
reply string converted from a byte array
- Return type:
str
- query_text(cmd)
Send a remote command and receive a reply with the lock acquired
- Parameters:
cmd (str) – remote command
- Return type:
str
- query_int(cmd)
Query for an integer-returning remote command
- Parameters:
cmd (str) – remote command
- Return type:
int
- query_float(cmd)
Query for a float-returning remote command
- Parameters:
cmd (str) – remote command
- Return type:
float
- set_timeout(seconds)
Set timeout for send and recv operation of the communication interface
- Parameters:
seconds (float) – timeout value
- get_timeout()
Get timeout value for send and recv operation of the communication interface
- Return type:
float
- query_text_with_long_timeout(cmd, timeout=30.0)
Query a command returning a delayed reply
- Parameters:
cmd (str) – remote command, such as CL, DG
timeout (int) – timeout value to use for the remote command
- Returns:
Error status byte
- Return type:
int
- get_info() dict
Return the interface information in a dict
srsgui.inst.communications.serialinterface module
- class srsgui.inst.communications.serialinterface.SerialInterface
Bases:
Interface
Interface to use RS232 serial communication
- NAME = 'serial'
- connect(port, baud_rate=115200, hardware_flow_control=False)
Connect to an instrument using the serial interface
- Parameters:
port (str) – serial port to use for serial communication, e.g., ‘COM3 for Windows, ‘/dev/ttyUSB0’ for Linux
baud_rate (integer, optional) – the default is 115200, You have to use the same baud rate with the connecting instrument.
hardware_flow_control (bool, optional) – the default is False, some instruments require RTS/CTS hardware flow control to work properly
- disconnect()
Disconnect from the communication interface
- static parse_parameter_string(param_string)
Parse a connection parameter string used in .taskconfig file
- send_break(duration=0.1)
Send break signal over serial interface
- Parameters:
duration (float, optioanl) – to set how long the break signal will be
- set_timeout(seconds)
Set timeout for send and recv operation of the communication interface
- Parameters:
seconds (float) – timeout value
- get_timeout()
Get timeout value for send and recv operation of the communication interface
- Return type:
float
- query_text(cmd)
Send a remote command and receive a reply with the lock acquired
- Parameters:
cmd (str) – remote command
- Return type:
str
- clear_buffer()
Read out any characters left in the communication buffer.
- get_info()
Get information on the communcation interface.
- classmethod find()
Find available serial ports and return a list of the ports.
srsgui.inst.communications.serial_ports module
Get all available serial ports.
Snippet from http://stackoverflow.com/questions/12090503/listing-available-com-ports-with-python
- srsgui.inst.communications.serial_ports.serial_ports()
Lists serial port names
- Raises:
EnvironmentError – On unsupported or unknown platforms
- Returns:
A list of the serial ports available on the system
srsgui.inst.communications.tcpipinterface module
- class srsgui.inst.communications.tcpipinterface.TcpipInterface
Bases:
Interface
Interface to use Ethernet TCP/IP communication
- NAME = 'tcpip'
- query_text(cmd)
Send a remote command and receive a reply with the lock acquired
- Parameters:
cmd (str) – remote command
- Return type:
str
- set_timeout(seconds)
Set timeout for send and recv operation of the communication interface
- Parameters:
seconds (float) – timeout value
- get_timeout()
Get timeout value for send and recv operation of the communication interface
- Return type:
float
- connect_without_login(ip_address, port=23)
Connect to a instrument that does not require login
- connect_with_login(ip_address, userid, password, port=818)
Connect and login to an instrument
- Parameters:
ip_address (str) – IP address of the instrument to connect, e.g., “192.168.1.100”
userid (str) – User name to login
password (str) – Password to login
port (int, optional) – the default is 818, SRS RGA port.
- connect(*args)
connect to the communication interface
Subclass will have its own connect arguments
- disconnect()
Disconnect from the communication interface
- static parse_parameter_string(param_string)
Parse a connection parameter string used in .taskconfig file
- clear_buffer()
It does not do anything for TCPIP interface
- get_info()
Return the interface information in a dict