diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2022-01-02 12:33:02 -0500 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2022-01-02 12:33:02 -0500 |
commit | 9f7ddb48286720734bdfe9dde644a95d1a47e642 (patch) | |
tree | 9e5a62d11525c7ef59fb50d05fee0feca7537542 /qolab/hardware | |
parent | 4c866a51ce479e61f2c417a529e64bee5063b431 (diff) | |
download | qolab-9f7ddb48286720734bdfe9dde644a95d1a47e642.tar.gz qolab-9f7ddb48286720734bdfe9dde644a95d1a47e642.zip |
small refining of the SCPI_PROPERTY
Diffstat (limited to 'qolab/hardware')
-rw-r--r-- | qolab/hardware/scpi.py | 30 |
1 files changed, 22 insertions, 8 deletions
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') |