aboutsummaryrefslogtreecommitdiff
path: root/qolab
diff options
context:
space:
mode:
Diffstat (limited to 'qolab')
-rw-r--r--qolab/hardware/scpi.py30
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')