aboutsummaryrefslogtreecommitdiff
path: root/qolab/hardware
diff options
context:
space:
mode:
Diffstat (limited to 'qolab/hardware')
-rw-r--r--qolab/hardware/scpi.py32
1 files changed, 27 insertions, 5 deletions
diff --git a/qolab/hardware/scpi.py b/qolab/hardware/scpi.py
index d80a546..ed7e30e 100644
--- a/qolab/hardware/scpi.py
+++ b/qolab/hardware/scpi.py
@@ -30,13 +30,29 @@ class SCPI_PROPERTY(property):
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'
+ no_getter - typical for some sort of command
+ no_setter - typical for measured values (i.e. external to the instrument)
"""
- def __init__(self, scpi_prfx=None, ptype=str, doc=None):
- super().__init__(fget=self.get_scpi, fset=self.set_scpi)
+ def __init__(self, scpi_prfx=None, ptype=str, doc=None, no_getter=False, no_setter=False):
+ self.no_getter = no_getter
+ self.no_setter = no_setter
+ if no_getter:
+ fget=None
+ else:
+ fget = self.get_scpi
+ if no_setter:
+ fset=None
+ else:
+ fset = self.set_scpi
+ super().__init__(fget=fget, fset=fset)
self.scpi_prfx = scpi_prfx
self.ptype = ptype
self.__doc__ = doc
+ def __set_name__(self, owner, name):
+ self.public_name = name
+ self.private_name = '_' + name
+
def get_scpi(self, owner):
return self.ptype( owner.query(f'{self.scpi_prfx}?') )
@@ -44,11 +60,12 @@ class SCPI_PROPERTY(property):
return owner.write(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.append( f'no_getter={self.no_getter}')
+ sargs.append( f'no_setter={self.no_setter}')
sargs =', '.join(sargs)
s = ''.join( [ f'{self.__class__.__name__}(' , sargs, ')' ] )
return s
@@ -118,6 +135,7 @@ if __name__ == '__main__':
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
+ # in order to check SCPI_PROPERTY we need to implement write and query
def write(self, str):
print(f'write: {str=}')
@@ -126,7 +144,11 @@ if __name__ == '__main__':
return '123'
x = SCPI_PROPERTY(scpi_prfx='SETX', ptype=str, doc='property X')
- y = SCPI_PROPERTY(scpi_prfx='SETY', ptype=int, doc='property Y')
+ y = SCPI_PROPERTY(scpi_prfx='SETY', ptype=int, no_setter=True, doc='property Y')
+ z = SCPI_PROPERTY(scpi_prfx='SETY', ptype=int, no_getter=True, doc='property Z')
- c= DummyInstrument()
+ c1= DummyInstrument()
+ c1.deviceProperties=['x', 'y']
+ c1.getConfig()
+ c2= DummyInstrument()