diff options
Diffstat (limited to 'qolab')
-rw-r--r-- | qolab/hardware/scpi.py | 64 |
1 files changed, 46 insertions, 18 deletions
diff --git a/qolab/hardware/scpi.py b/qolab/hardware/scpi.py index a9641cf..92c949e 100644 --- a/qolab/hardware/scpi.py +++ b/qolab/hardware/scpi.py @@ -11,10 +11,24 @@ logger = logging.getLogger('qolab.hardware.scpi') logger.setLevel(logging.INFO) def response2numStr(strIn, firstSeparator=None, unit=None): - # Often an instrument reply is in the form 'TDIV 2.00E-08S' (for example Siglent Scope) - # i.e. "<prefix><firstSeparator><numberString><unit> - # prefix='TDIV', firstSeparator=' ', numberString='2.00E-08', unit='S' - # this function parses the reply + """Parses non standard SCPI reply. + Often an instrument reply is in the form 'TDIV 2.00E-08S' (for example Siglent Scope) + i.e. "<prefix><firstSeparator><numberString><unit> where + prefix='TDIV', firstSeparator=' ', numberString='2.00E-08', unit='S' + + Parameters + ---------- + prefix : str + reply prefix, e.g. 'TDIV' + firstSeparator : str + separator between numerical part and prefix, e.g. ' ' + unit: str + unit used in the reply, e.g. 'S' + + Returns + ------- + (prefix, numberString, unit) tuple + """ prefix = None rstr = strIn if firstSeparator is not None and firstSeparator != '': @@ -31,20 +45,35 @@ def response2numStr(strIn, firstSeparator=None, unit=None): return (prefix, numberString, unit) class SCPI_PROPERTY(property): - """ - Overrides property class and makes it suitable for SCPI set and query notation. + """Overrides 'property' class and makes it suitable for SCPI set and query notation. + Adds ability to log into TSDB. Works within SCPIinstr class since it assumes that owner has query() and write(). - scpi_prfx - SCPI command prefix to get/set property, for example 'FreqInt' - is internally transformed to - query 'FreqInt?' and setter 'FreqInt {val}'. - It could be set as the explicit query and set format string list: - ['AUXV? 1', 'AUXV 1,{}'] where {} is place holder for set value - ptype - property type 'str', 'int', 'float', ... - doc - short description of property, for example 'Internal lockin frequency' - no_getter - typical for some sort of command - no_setter - typical for measured values (i.e. external to the instrument) - tsdb_logging - logging to time series DB (True/False) + + Parameters + ---------- + scpi_prfx : str or None (default) + SCPI command prefix to get/set property, for example 'FreqInt' + is internally transformed to + query 'FreqInt?' and setter 'FreqInt {val}'. + It could be set as the explicit query and set format string list: + ['AUXV? 1', 'AUXV 1,{}'] where {} is place holder for set value + ptype : type, str is default + property type 'str', 'int', 'float', ... + doc : str or None (default) + short description of property, for example 'Internal lockin frequency' + no_getter: True of False (default) + does property has a getter, some properties has no getter, e.g. output voldage of a DAC + no_setter : True of False (default) + does property has a setter, some properties has no setter, e.g. measurement of external voltages for an ADC + tsdb_logging : True (default) or False + do we log get/set commands result/argument to TSDB + + Examples + -------- + x = SCPI_PROPERTY(scpi_prfx='SETX', ptype=str, doc='property X', tsdb_logging=False) + """ + def __init__(self, scpi_prfx=None, ptype=str, doc=None, no_getter=False, no_setter=False, tsdb_logging=True): self.no_getter = no_getter self.no_setter = no_setter @@ -124,8 +153,7 @@ class SCPI_PROPERTY(property): return s class SCPIinstr: - """ Basic class which support SCPI commands """ - """ + """ Basic class which support SCPI commands. Do not instantiate directly, use rm = pyvisa.ResourceManager() SCPIinstr(rm.open_resource('TCPIP::192.168.0.2::INSTR')) |