scpi_instrument
SCPI Instrument interface and associated decorator tools.
This module contains the SCPIInstrument interface, and several function factories for creating input verifiers for SCPI set commands.
Verifiers include: verifier_or, truthy, is_numeric, is_integer.
Functions
|
Verifier factory for "in"-type verifiers. |
|
Verifier factory for integer verifiers. |
|
Verifier factory for numeric verifiers. |
|
Verifier factory for "map"-type verifiers. |
|
Verifier factory for truthy verifiers. |
|
Verifier factory to combine multiple verifiers in OR-like behaviour. |
Classes
|
Implementation of a VisaInstrument to communicate with devices accepting SCPI- like (query-set) command structures. |
Exceptions
is_in
- icicle.scpi_instrument.is_in(*array, to_upper=False)
Verifier factory for “in”-type verifiers.
- Parameters:
array... – items in list of acceptable input values.
- Returns:
Verifier function.
Note
FUNCTION FACTORY
is_integer
- icicle.scpi_instrument.is_integer(min=None, max=None, scale=1)
Verifier factory for integer verifiers.
- Parameters:
min – Minimum input number to accept.
false_output – Maximal input number to accept.
- Returns:
Verifier function.
Note
FUNCTION FACTORY
is_numeric
- icicle.scpi_instrument.is_numeric(min=None, max=None, scale=1, to_int=False)
Verifier factory for numeric verifiers. Resulting verifiers always return original type, or float if converted from string.
- Parameters:
min – Minimum input number to accept.
false_output – Maximal input number to accept.
- Returns:
Verifier function.
Note
FUNCTION FACTORY
map_to
- icicle.scpi_instrument.map_to(mapping, to_upper=False)
Verifier factory for “map”-type verifiers.
- Parameters:
mapping – dictionary of acceptable input values and mapped output values.
- Returns:
Verifier function.
Note
FUNCTION FACTORY
truthy
- icicle.scpi_instrument.truthy(true_output=1, false_output=0, true_like=(True, 1, '1', 'ON', 'Y', 'YES', 'TRUE'), false_like=(False, 0, '0', 'OFF', 'N', 'NO', 'FALSE'))
Verifier factory for truthy verifiers. What is truthy is controlled by true_like, false_like lists.
- Parameters:
true_output – What to return if input is “truthy”.
false_output – What to return if input is NOT “truthy”.
true_like – List of things that should resolve to true_output.
false_like – List of things that should resolve to false_output.
- Returns:
Verifier function.
Note
FUNCTION FACTORY
verifier_or
- icicle.scpi_instrument.verifier_or(*verifiers)
Verifier factory to combine multiple verifiers in OR-like behaviour.
- Parameters:
verifiers... – multiple verifiers (functions) to combined.
- Returns:
Verifier function.
Note
FUNCTION FACTORY
SCPIInstrument
- class icicle.scpi_instrument.SCPIInstrument(*args, **kwargs)
Bases:
VisaInstrument
Implementation of a VisaInstrument to communicate with devices accepting SCPI- like (query-set) command structures.
- __init__(resource='ASRL/dev/ttyUSB1::INSTR', sim=False)
- Parameters:
resource – VISA Resource address. See VISA docs for more info.
- COM_RESET = '*RST; STATUS:PRESET; *CLS'
- READ_TERMINATION = '\n'
Read termination characters.
- SETTINGS = {'IDENTIFIER': {'QUERY': '*IDN?'}}
- SET_REQUIRES_READBACK = False
Either False, or True, or a callable to be executed after a readback with signature set_requires_feedback(instrument, command, value, readback_value).
If True or callable, a readback is performed directly after a call to set(), before any query(). If False, it is assumed the device does not respond to set().
- SMALL_DELAY = 0.05
Small delay between subsequent commands (s).
- TIMEOUT = 10000
Link timeout (ms).
- WRITE_TERMINATION = '\n'
Write termination characters.
- identify(**kwargs)
Query *IDN for device identifier.
- Parameters:
no_lock – override acquire_lock (e.g. if lock already taken by function that reset-call is nested within).
attempts – how many retries to give query command.
- query(setting, *params)
Query setting on instrument.
- Parameters:
setting – key in class dictionary SETTINGS.
no_lock – override acquire_lock (e.g. if lock already taken by function that query-call is nested within).
attempts – how many retries to give query command.
- Returns:
Data returned by device for given query.
- reset()
Reset device using the provided COM_RESET command within the class implementation.
- set(setting, *value, check_readback_only=False)
Set setting on instrument to value, and read-back using equivalent query().
- Parameters:
setting – key in class dictionary SETTINGS.
value – target value for setting.
check_readback_only – how to only check readback value if SET_REQUIRES_READBACK is set, and not perform back-query. If ‘same’, checks that readback gives same command as was sent.
no_lock – override acquire_lock (e.g. if lock already taken by function that set-call is nested within).
attempts – how many retries to give set command.
- Returns:
Read-back value if query() available, else whether number of bytes written during set() meets expectation
ValidationError
- icicle.scpi_instrument.ValidationError()
Unspecified run-time error.