SCPI Class¶
-
class
scpi.
SCPI
(cmd_list, comm_handle, name='not named', unconnected=False)[source]¶ A SCPI (or SCPI like) instrument with a list of commands. The instrument has methods to get and set info of each command.
Parameters: - cmd_list : Command
A list of commands. Each command is an object of the class Command
- comm_handle : Communication object
handle to the (general) hardware interface Example is the pyvisa instrument object: inst Needed when commands are overriden must have a:
write method (Examples are pySerial write() or pyvisa inst.write()) and an ask method (Examples are pySerial ask() and pyvisa inst.query())
- name : str, optional
Name of the instrument
- unconnected : bool, optional
For simulation & testing without instruments If true a “fake” ask and write command are configured. Ask always returns the same value (getter_debug_value).
Attributes: - unconnected : bool
if True the instrument is unconnected and returns appropriately configured garbage values just for testing
- vendor_id : str
id returned by the identification command
- name : str
name the user assigns
- comm_handle : object
the communication object (could be from pyvisa or pyserial)
Methods
get(name, configs={}) : get the value for the command of a given name set(name, value=None, configs={}) : set a value for the command of name list_cmds() : print all cmds help_all(subsystem_list=None) : list help for all commands (or for commands within a list of subsystems) help(name): print help on a command of the provided name log_all_getters(filename=None, suppress_stdout=False): write all values that can be read to a file or to stdout test_command(name, set_vals=None, get_configs={}, set_configs={}): test a specific command by sending a value and checking the readback of that value test_all(skip_subsystem=[‘setup’, ‘status’, ‘system’], skip_commands=[‘fast_transfer’, ‘reset’]) : test all commands -
check_set_range
(value, name)[source]¶ check if the value to be set is within range
Parameters: - name : string
name of the command (first column in the csv file)
- value : Union[str, int, float, None]
the value to set
Returns: - bool
True if in range
-
help_all
(subsystem_list=None)[source]¶ print help for all commands
Parameters: - subsystem_list : list, optional
a list of subsystems to limit the printing to
- name : string
name of the command (first column in the csv file)
-
log_all_getters
(filename=None, suppress_stdout=False)[source]¶ save all gettable values to a file and send to stdout
Parameters: - filename : str, optional
name of the file (if None no file is saved)
- suppress_stdout : bool, optional
if True the getters will not be printed to stdout
Returns: - dict
dictionary with the command name as keys and the results as values
-
out_of_range_warning
(value, name)[source]¶ throw a warning
Parameters: - value : Union[str, int, float, None]
the value to set
- name : string
name of the command (first column in the csv file)
Returns: - UserWarning
-
read_comm_err
()[source]¶ - Read if the instrument has flagged a communciation error
- The csv command file must have a getter with name comm_error that returns a bool
Returns: - bool
if True a comm error was detected
-
set
(name, value=None, configs={})[source]¶ set a value
Parameters: - name : string
name of the command (first column in the csv file)
- value : Union[str, int, float, None]
the value to set
- configs : dict, optional
special configurations beyond the ‘value’; specified in the csv file
Returns: - str
Todo
check this and fix?
-
test_all
(skip_subsystem=['setup', 'status', 'system'], skip_commands=['fast_transfer', 'reset'])[source]¶ Test all commands by setting and getting to determine if: 1) the instrument reports a communcation error 2) the return value is of an unexpected type or an error threshold away from what was set
Parameters: - skip_subsystem : list (of strings), default = [‘setup’, ‘status’]
subsystems to skip, an example might be commands in the status subsystem that reset the instrument
- skip_commands : list (of strings), default = [‘fast_transfer’, ‘reset’]
Commands to skip
Returns: - dict
Keys are each commands tested, value is True (command succeeded) or False (command errored)
-
test_command
(name, set_vals=None, get_configs={}, set_configs={})[source]¶ Test a command by setting and getting to determine if: 1) the instrument reports a communcation error 2) the return value is of an unexpected type or an error threshold away from what was set
Parameters: - name : str
Name of the command
- set_vals : list, optional
A list of values to test by a sequence of set and get. If not provided the low and high limits are used
- get_configs : dict, optional
A dictionary of configs to send the get command
- set_configs : dict, optional
A dictionary of configs to send the set command
Returns: - bool
True if the command is successful, False otherwise.