diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2022-01-02 00:59:43 -0500 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2022-01-02 00:59:43 -0500 |
commit | 4c866a51ce479e61f2c417a529e64bee5063b431 (patch) | |
tree | fc019f92209e6c1f7606ed1fa1800a7b0100630f /qolab/hardware | |
parent | d83b95b5b5254ec391759a79fe2edb0ff8ced794 (diff) | |
download | pyExpControl-4c866a51ce479e61f2c417a529e64bee5063b431.tar.gz pyExpControl-4c866a51ce479e61f2c417a529e64bee5063b431.zip |
draft of SCPI_PROPERTY to simplify set/query operations
Diffstat (limited to 'qolab/hardware')
-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() + |