From 4c866a51ce479e61f2c417a529e64bee5063b431 Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Sun, 2 Jan 2022 00:59:43 -0500 Subject: draft of SCPI_PROPERTY to simplify set/query operations --- qolab/hardware/scpi.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'qolab/hardware') 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() + -- cgit v1.2.3