diff options
Diffstat (limited to 'qolab/hardware/scpi.py')
-rw-r--r-- | qolab/hardware/scpi.py | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/qolab/hardware/scpi.py b/qolab/hardware/scpi.py index 6f4037d..8d7248d 100644 --- a/qolab/hardware/scpi.py +++ b/qolab/hardware/scpi.py @@ -33,7 +33,10 @@ class SCPI_PROPERTY(property): Overrides property class and makes it suitable for SCPI set and query notation. 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' - query formed as 'scpi_prfx?' and setter as 'scpi_prfx val' + 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 @@ -56,6 +59,21 @@ class SCPI_PROPERTY(property): self.scpi_prfx = scpi_prfx self.ptype = ptype self.__doc__ = doc + if isinstance(scpi_prfx, str): + self.scpi_prfx_get = ''.join([self.scpi_prfx, '?']) + self.scpi_prfx_set = ''.join([self.scpi_prfx, ' {}']) + elif isinstance(scpi_prfx, list): + if len(scpi_prfx) != 2: + raise ValueError(f'{scpi_prfx=}, should be list with exactly two elements') + self.scpi_prfx_get = self.scpi_prfx[0] + self.scpi_prfx_set = self.scpi_prfx[1] + else: + raise ValueError(f'{scpi_prfx=}, it should be either str or list type') + + if not isinstance(self.scpi_prfx_get, str): + raise ValueError(f'{self.scpi_prfx_get=}, it should be str type') + if not isinstance(self.scpi_prfx_set, str): + raise ValueError(f'{self.scpi_prfx_set=}, it should be str type') def __set_name__(self, owner, name): self.public_name = name @@ -82,12 +100,13 @@ class SCPI_PROPERTY(property): def get_scpi(self, owner): - val = self.ptype( owner.query(f'{self.scpi_prfx}?') ) + val = self.ptype( owner.query(f'{self.scpi_prfx_get}') ) self.log_to_tsdb(owner, action='get', val=val) return val def set_scpi(self, owner, val): - owner.write(f'{self.scpi_prfx} {val}') + cstr = self.scpi_prfx_set.format(val) + owner.write(cstr) self.log_to_tsdb(owner, action='set', val=val) def __repr__(self): |