From 9f7ddb48286720734bdfe9dde644a95d1a47e642 Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Sun, 2 Jan 2022 12:33:02 -0500 Subject: small refining of the SCPI_PROPERTY --- qolab/hardware/scpi.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'qolab') diff --git a/qolab/hardware/scpi.py b/qolab/hardware/scpi.py index 42f25b4..d80a546 100644 --- a/qolab/hardware/scpi.py +++ b/qolab/hardware/scpi.py @@ -23,7 +23,14 @@ 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. + 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' + ptype - property type 'str', 'int', 'float', ... + doc - short description of property, for example 'Internal lockin frequency' + """ 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 @@ -31,11 +38,10 @@ class SCPI_PROPERTY(property): self.__doc__ = doc def get_scpi(self, owner): - print(f'{self.scpi_prfx}?') - return self.ptype( '443' ) + return self.ptype( owner.query(f'{self.scpi_prfx}?') ) def set_scpi(self, owner, val): - print(f'{self.scpi_prfx} {val}') + return owner.write(f'{self.scpi_prfx} {val}') def __repr__(self): s = [ f'{self.__class__.__name__}(' ] @@ -107,10 +113,18 @@ class SCPIinstr: if __name__ == '__main__': - class DummyInstrument(): - def fz(self): - """ I am fz """ - return 34 + from qolab.hardware.basic import BasicInstrument + class DummyInstrument(BasicInstrument): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def write(self, str): + print(f'write: {str=}') + + def query(self, str): + print(f'query: {str=}') + return '123' + x = SCPI_PROPERTY(scpi_prfx='SETX', ptype=str, doc='property X') y = SCPI_PROPERTY(scpi_prfx='SETY', ptype=int, doc='property Y') -- cgit v1.2.3