diff options
Diffstat (limited to 'qolab/hardware/scpi.py')
-rw-r--r-- | qolab/hardware/scpi.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/qolab/hardware/scpi.py b/qolab/hardware/scpi.py index b4111b3..42f25b4 100644 --- a/qolab/hardware/scpi.py +++ b/qolab/hardware/scpi.py @@ -22,6 +22,30 @@ def response2numStr(strIn, firstSeparator=None, unit=None): numberString = rstr return (prefix, numberString, unit) +class SCPI_PROPERTY(property): + """ Overrides property class and makes it suitable for SCPI set and query notation """ + def __init__(self, scpi_prfx=None, ptype=str, doc=None): + super().__init__(fget=self.get_scpi, fset=self.set_scpi) + self.scpi_prfx = scpi_prfx + self.ptype = ptype + self.__doc__ = doc + + def get_scpi(self, owner): + print(f'{self.scpi_prfx}?') + return self.ptype( '443' ) + + def set_scpi(self, owner, val): + print(f'{self.scpi_prfx} {val}') + + def __repr__(self): + s = [ f'{self.__class__.__name__}(' ] + sargs= [] + sargs.append( f'scpi_prfx={self.scpi_prfx}') + sargs.append( f'ptype={self.ptype}') + sargs.append( f'doc={self.__doc__}') + sargs =', '.join(sargs) + s = ''.join( [ f'{self.__class__.__name__}(' , sargs, ')' ] ) + return s class SCPIinstr: """ Basic class which support SCPI commands """ @@ -82,3 +106,13 @@ class SCPIinstr: self.write("*WAI") +if __name__ == '__main__': + class DummyInstrument(): + def fz(self): + """ I am fz """ + return 34 + x = SCPI_PROPERTY(scpi_prfx='SETX', ptype=str, doc='property X') + y = SCPI_PROPERTY(scpi_prfx='SETY', ptype=int, doc='property Y') + + c= DummyInstrument() + |