aboutsummaryrefslogtreecommitdiff
path: root/qolab
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2022-01-02 14:24:23 -0500
committerEugeniy E. Mikhailov <evgmik@gmail.com>2022-01-02 14:25:07 -0500
commita486f5fecf9607fd024eef3d92ff3f7928b40f59 (patch)
tree384dd46d79f903ac243ea64a301c95b3d635d778 /qolab
parent9f7ddb48286720734bdfe9dde644a95d1a47e642 (diff)
downloadpyExpControl-a486f5fecf9607fd024eef3d92ff3f7928b40f59.tar.gz
pyExpControl-a486f5fecf9607fd024eef3d92ff3f7928b40f59.zip
added no_getter and no_setter
Diffstat (limited to 'qolab')
-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()