srsgui.inst package
- srsgui.inst.communications package
- srsgui.inst.communications.interface module
Interface
Interface.NAME
Interface.set_callbacks()
Interface.get_lock()
Interface.connect()
Interface.disconnect()
Interface.is_connected()
Interface.parse_parameter_string()
Interface.set_term_char()
Interface.get_term_char()
Interface.send()
Interface.recv()
Interface.query_text()
Interface.query_int()
Interface.query_float()
Interface.set_timeout()
Interface.get_timeout()
Interface.query_text_with_long_timeout()
Interface.get_info()
- srsgui.inst.communications.serialinterface module
SerialInterface
SerialInterface.NAME
SerialInterface.connect()
SerialInterface.disconnect()
SerialInterface.parse_parameter_string()
SerialInterface.send_break()
SerialInterface.set_timeout()
SerialInterface.get_timeout()
SerialInterface.query_text()
SerialInterface.clear_buffer()
SerialInterface.get_info()
SerialInterface.find()
- srsgui.inst.communications.serial_ports module
- srsgui.inst.communications.tcpipinterface module
TcpipInterface
TcpipInterface.NAME
TcpipInterface.query_text()
TcpipInterface.set_timeout()
TcpipInterface.get_timeout()
TcpipInterface.connect_without_login()
TcpipInterface.connect_with_login()
TcpipInterface.connect()
TcpipInterface.disconnect()
TcpipInterface.parse_parameter_string()
TcpipInterface.clear_buffer()
TcpipInterface.get_info()
- srsgui.inst.communications.interface module
srsgui.inst.instrument module
- class srsgui.inst.instrument.Instrument(interface_type=None, *args)
Bases:
Component
Base class for derived instrument classes.
- available_interfaces = [[<class 'srsgui.inst.communications.serialinterface.SerialInterface'>, {'baud_rate': <srsgui.task.inputs.IntegerListInput object>, 'hardware_flow_control': <srsgui.task.inputs.BoolInput object>, 'port': <srsgui.task.inputs.FindListInput object>}], [<class 'srsgui.inst.communications.tcpipinterface.TcpipInterface'>, {'ip_address': <srsgui.task.inputs.Ip4Input object>, 'port': <srsgui.task.inputs.IntegerInput object>}]]
Available_interface specifies the communication interface available with an instrument. As default, SerialInterface and TcpipInterface is provided with the base class. VXI11 interface and VISA interface is available srsinst.sr860 package.
- connect(interface_type, *args)
Connect to an instrument over one of the specified communication interfaces in available_interface
If interface_type is ‘serial’,
- Parameters:
interface_type (str) – Use ‘serial’ for serial communication
port (string) – serial port, such as ‘COM3’ or ‘/dev/ttyUSB0’
baud_rate (int, optional) – baud rate of the serial port, default is 114200, and SRS RGA uses 28800.
hardware_flow_control (bool, optional) – RTS/CTS setting. The default is False, SRS RGA requires True.
If interface_type is ‘tcpip’,
- Parameters:
interface_type (str) – Use ‘tcpip’ for TCPIP communication
ip_address (str) – IP address of a instrument, such as ‘192.168.1.100’
port (int, optional) – TCP port number, default is 23 which is the TELNET default port.
- disconnect()
Disconnect from the instrument
- is_connected()
Check if the communication interface is connected.
- Return type:
bool
- set_term_char(ch)
Set the termination character for the communication interface
- Parameters:
ch (bytes) – termination character
- get_term_char()
Get the current termination character
- Returns:
termination character for the communication interface
- Return type:
bytes
- send(cmd)
Send a remote command without a reply
- Parameters:
cmd (str) – remote command
- query_text(cmd)
Send a remote command with a string reply, and return the reply as a string.
- Parameters:
cmd (str) – remote command
- Returns:
reply of the remote command
- Return type:
str
- query_int(cmd)
Send a remote command with a integer reply, and return the reply as a integer.
- Parameters:
cmd (str) – remote command
- Returns:
reply of the remote command
- Return type:
int
- query_float(cmd)
Send a remote command with a float reply, and return the reply as a float.
- Parameters:
cmd (str) – remote command
- Returns:
reply of the remote command
- Return type:
float
- check_id()
Check if the ID string of the instrument contains _IdString of the Instrument class. A derived instrument class should make sure that check_id() method is properly implemented.
- Returns:
tuple of (model name, serial number, firmware version)
- classmethod get_available_interfaces()
Get available communication interfaces for the instrument
- Return type:
dict
- get_info()
Get the instrument information
default return value is a dictionary containing model name, serial number, firmware version. A subclass can add more information into the dictionary as needed.
- Return type:
dict
- get_status()
Get instrument status
Returns a string with stauts and error infomation. This method will be called by the owner of the instrument to display status info to its output interface.
- Return type:
str
- handle_command(cmd)
It sends a remote command and returns the reply, if the remote command returns a reply. if the remote command has no replay, it return a empty string. A terminal program will always get a reply for any remote command, unless unexpected timeout error occurs
- Parameters:
cmd (str) – remote command
- reset()
Reset the instrument.
- connect_with_parameter_string(parameter_string)
Connect the instrument using colon-separated parameter string from a config file
- exclude_capture = [<function Instrument.connect_with_parameter_string>]
Exclude commands from query in capture_commands
srsgui.inst.component module
- class srsgui.inst.component.Component(parent, name='unnamed')
Bases:
object
Class used to build hierarchical structure in an instrument.
An instrument can have multiple components and each component can also have multiple subcomponents. All the components inside an instrument shares the communication interface of the instrument.
When the communication interface of an instrument changed, the instrument should call
update_components()
to update all its components.Component has a convenience attribute,
dir
that returns available subcomponents, commands and methods available from the component.dir
combines the return values fromget_component_dict()
,get_command_dict()
andget_method_list()
.Component has a convenience method,
get_component_dict()
to get child components of an instance. This method helps a user to navigate through the component tree.Component contains Command and its subclasses along with IndexCommand and its subclasses as class attributes. A convenience method,
get_command_dict()
will show what commands are available from the component instance. each command is listed with: the name of the Command instance; the raw remote command associated with the command; the conversion_dict if it is a DictCommand instance; the index_dict for IndexCommand instance, if used.get_method_list()
shows methods a component has, including ones inherited from the superclasses.The information available from the convenience methods are available interactively from context-sensitive editors, such as IDLE, Pycharm, VSCode. When the information from the editors are not complete, consulting with those convenience methods provides complete lists you can use.
- dir = None
Attribute to be used to get a dictionary that contains information on the subcomponents, commands, and class method
- exclude_capture = []
Exclude commands from query in capture_commands
- allow_run_button = []
Allow methods to have run buttons in the GUI control panel
- is_connected()
check if the current communication interface is open
- set_name(name)
Set the name of the component
- get_name()
Get the name of the component
- update_components()
Update the communication interface of child components with the parent’s
- get_lists(include_superclass=True)
Get the directory containing a list of subcomponents in this component, a list of commands available in the component, a list of method available in the component and its superclass
- get_component_dict()
Get a dict of the child component of the component
- Returns:
list contain name of child compoents and its class name
- Return type:
list(str)
- get_command_dict(include_superclass=False)
Get a dict of commands available from the component.
list contains strings on command name, command type, remote command it uses
- Returns:
list of commands
- Return type:
list(str)
- get_method_list(include_superclass=False)
get a list of names of methods available from the component including methods inherited from the superclasses
- Returns:
list of string of method names
- Return type:
list(str)
- get_command_info(command_name)
get detailed information on the command with command_name
- Returns:
dictionary of information on the command
- Return type:
dict
- assert_command_key(command, key)
It asserts if the component has the command as a DictCommand and DictIndexCommand, and the command has the key in its set_dict.
- capture_commands(include_query_only=False, include_set_only=False, include_excluded=False, include_methods=False, show_raw_cmds=False)
Query all commands with both set and get methods in the component and its subcomponents
srsgui.inst.commands module
Module to wrap remote commands used in communication with an instrument in Python descriptors.
If an instrument has a remote command ‘FREQ’ for setting and querying a value, you will use the command from a terminal,
> FREQ?
1000.0
? FREQ 500
> FREQ?
500.0
The instrument is defined as an instance of an Instrument subclass, fg, you can use it from a Python interpreter prompt.
>>> fg.query_float('FREQ?')
1000.0
>>> fg.send('FREQ 500')
>>> fg.query_float('FREQ?')
500.0
You can define a FloatCommand for the remote command in an Instrument subclass.
frequency = FloatCommand(‘FREQ’)
Now, you can use the command like an class attribute as following:
>>> fg.frequency
1000.0
>>> fg.frequency = 500
>>> fg.frequency
500.0
Using Command class simplifies tedious usage of a many set and query remote commands
- class srsgui.inst.commands.Command(remote_command_name, default_value=None)
Bases:
object
Descriptor for a remote command to set and query a string value
- class srsgui.inst.commands.GetCommand(remote_command_name, default_value=None)
Bases:
Command
Descriptor for a remote command only to query a string value. To set a value is not allowed.
- class srsgui.inst.commands.SetCommand(remote_command_name, default_value=None)
Bases:
Command
Descriptor for a remote command only to set a string value. To query a value is not allowed.
- class srsgui.inst.commands.BoolCommand(remote_command_name, default_value=None)
Bases:
Command
Descriptor for a remote command to set and query a bool value
- class srsgui.inst.commands.BoolGetCommand(remote_command_name, default_value=None)
Bases:
BoolCommand
Descriptor for a remote command only to query a bool value. To set a value is not allowed.
- class srsgui.inst.commands.BoolSetCommand(remote_command_name, default_value=None)
Bases:
BoolCommand
Descriptor for a remote command only to set a bool value. To query a value is not allowed.
- class srsgui.inst.commands.IntCommand(remote_command_name, unit='', min=0, max=65535, step=1, default_value=None)
Bases:
Command
Descriptor for a remote command to set and query an integer value
- class srsgui.inst.commands.IntGetCommand(remote_command_name, unit='', min=0, max=65535, step=1, default_value=None)
Bases:
IntCommand
Descriptor for a remote command only to query an integer value. To set a value is not allowed.
- class srsgui.inst.commands.IntSetCommand(remote_command_name, unit='', min=0, max=65535, step=1, default_value=None)
Bases:
IntCommand
Descriptor for a remote command only to set an integer value. To query a value is not allowed.
- class srsgui.inst.commands.FloatCommand(remote_command_name, unit='', min=-1000000.0, max=1000000.0, step=1e-09, significant_figures=4, default_value=None)
Bases:
Command
Descriptor for a remote command to set and query a float value
- class srsgui.inst.commands.FloatGetCommand(remote_command_name, unit='', min=-1000000.0, max=1000000.0, step=1e-09, significant_figures=4, default_value=None)
Bases:
FloatCommand
Descriptor for a remote command only to query a float value. To set a value is not allowed.
- class srsgui.inst.commands.FloatSetCommand(remote_command_name, unit='', min=-1000000.0, max=1000000.0, step=1e-09, significant_figures=4, default_value=None)
Bases:
FloatCommand
Descriptor for a remote command only to set a float value. To query a value is not allowed.
- class srsgui.inst.commands.DictCommand(remote_command_name, set_dict, get_dict=None, unit='', fmt='', default_value=None)
Bases:
Command
Descriptor for a remote command to set and query using a conversion dictionary
- key_to_value(key)
- value_to_key(value)
- class srsgui.inst.commands.DictGetCommand(remote_command_name, set_dict, get_dict=None, unit='', fmt='', default_value=None)
Bases:
DictCommand
Descriptor for a remote command only to query a dict value. To set a value is not allowed.
srsgui.inst.indexcommands module
Module to wrap remote commands with an index argument in dunder methods, __setitem__ and __get_item__.
If an instrument has a remote command using an index, ‘PARAM’, for setting and querying a value, you will use the command from a terminal,
> PARAM? 1
1000.0
? PARAM 1, 500
> PARAM? 1
500.0
The instrument is defined as an instance of an Instrument subclass, fg
,
you can use it from a Python interpreter prompt.
>>> fg.query_float('PARAM? 1')
1000.0
>>> fg.send('PARAM 1, 500')
>>> fg.query_float('PARAM? 1')
500.0
You can define a FloatIndexCommand for the remote command in an Instrument subclass.
>>> fit_parameter = FloatIndexCommand('PARAM', index_max=3)
Now, you can use the command like an class attribute as following:
>>> fg.fit_parameter[1]
1000.0
>>> fg.fit_parameter[1] = 500
>>> fg.fit_parameter[1]
500.0
Sometimes, it is hard to remember whtat a n index means for the command. You can assign an index_dict to use the dictionary keys instead of the numberic index.
>>> IndexDict = {'front': 0, 'back': 1, 'left':2, 'right':3}
>>> fit_parameter = FloatIndexCommand('PARAM', index_max=3, index_min=0, index_dict=IndexDict)
>>> fg.fit_parameter['back']
500.0
>>> fg.fit_parameter['back'] = 1000
>>> fg.fit_parameter['back']
1000.0
Using IndexCommand class simplifies tedious usage of a many set and query remote commands with an index argument
- class srsgui.inst.indexcommands.IndexCommand(remote_command_name, index_max, index_min=0, index_dict=None)
Bases:
object
Command class for a remote command with index using set and query returning an string
- class srsgui.inst.indexcommands.IndexGetCommand(remote_command_name, index_max, index_min=0, index_dict=None)
Bases:
IndexCommand
Command class for a remote command with index using only query returning an string, without set.
- class srsgui.inst.indexcommands.BoolIndexCommand(remote_command_name, index_max, index_min=0, index_dict=None)
Bases:
IndexCommand
Command class for a remote command with index using set and query returning a bool
- class srsgui.inst.indexcommands.BoolIndexGetCommand(remote_command_name, index_max, index_min=0, index_dict=None)
Bases:
BoolIndexCommand
Command class for a remote command with index using only query returning a bool, without set.
- class srsgui.inst.indexcommands.IntIndexCommand(remote_command_name, index_max, index_min=0, index_dict=None, unit='', value_min=0, value_nax=65535, step=1)
Bases:
IndexCommand
Command class for a remote command with index using set and query returning an integer
- class srsgui.inst.indexcommands.IntIndexGetCommand(remote_command_name, index_max, index_min=0, index_dict=None, unit='', value_min=0, value_nax=65535, step=1)
Bases:
IntIndexCommand
Command class for a remote command with index using only query returning an integer, without set.
- class srsgui.inst.indexcommands.FloatIndexCommand(remote_command_name, index_max, index_min=0, index_dict=None, unit='', value_min=-1000000.0, value_max=1000000.0, step=1e-09, significant_figures=4, default_valaue=0.0)
Bases:
IndexCommand
Command class for a remote command with index using set and query returning an float
- class srsgui.inst.indexcommands.FloatIndexGetCommand(remote_command_name, index_max, index_min=0, index_dict=None, unit='', value_min=-1000000.0, value_max=1000000.0, step=1e-09, significant_figures=4, default_valaue=0.0)
Bases:
FloatIndexCommand
Command class for a remote command with index using only query returning an float, without set.
- class srsgui.inst.indexcommands.DictIndexCommand(remote_command_name, set_dict, index_max, index_min=0, index_dict=None, get_dict=None, unit='')
Bases:
IndexCommand
Descriptor for a remote command to set and query using a conversion dictionary
- key_to_value(key)
- value_to_key(value)
srsgui.inst.exceptions module
- exception srsgui.inst.exceptions.InstException
Bases:
Exception
Package-wide base exception
- exception srsgui.inst.exceptions.InstCommunicationError
Bases:
InstException
communication exception
- exception srsgui.inst.exceptions.InstLoginFailureError
Bases:
InstException
Exception for TCPIP login error
- exception srsgui.inst.exceptions.InstIdError
Bases:
InstException
Exception for invalid instrument ID
- exception srsgui.inst.exceptions.InstSetError
Bases:
InstException
Exception for errors during set operation
- exception srsgui.inst.exceptions.InstQueryError
Bases:
InstException
Exception for errors during query operation
- exception srsgui.inst.exceptions.InstIndexError
Bases:
InstException
Exception for error in index operation