frappy_psi.ah2700: fixes
This commit is contained in:
@@ -29,7 +29,7 @@ an empty name
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from frappy.core import FloatRange, HasIO, Parameter, Readable, StringIO, nopoll, \
|
from frappy.core import FloatRange, HasIO, Parameter, Readable, StringIO, nopoll, \
|
||||||
Attached, Property, StringType
|
Attached, Property, StringType, Writable
|
||||||
from frappy.dynamic import Pinata
|
from frappy.dynamic import Pinata
|
||||||
|
|
||||||
|
|
||||||
@@ -47,6 +47,11 @@ class Capacitance(HasIO, Pinata, Readable):
|
|||||||
configure '' to disable the creation of the loss module
|
configure '' to disable the creation of the loss module
|
||||||
''',
|
''',
|
||||||
StringType(), default='$_loss')
|
StringType(), default='$_loss')
|
||||||
|
freq_name = Property('''name of freq module
|
||||||
|
|
||||||
|
default: not created
|
||||||
|
''',
|
||||||
|
StringType(), default='')
|
||||||
|
|
||||||
ioClass = Ah2700IO
|
ioClass = Ah2700IO
|
||||||
loss = 0 # not a parameter
|
loss = 0 # not a parameter
|
||||||
@@ -59,6 +64,11 @@ class Capacitance(HasIO, Pinata, Readable):
|
|||||||
'cls': Loss,
|
'cls': Loss,
|
||||||
'description': f'loss value of {self.name}',
|
'description': f'loss value of {self.name}',
|
||||||
'cap': self.name}
|
'cap': self.name}
|
||||||
|
if self.freq_name:
|
||||||
|
yield self.freq_name.replace('$', self.name), {
|
||||||
|
'cls': Freq,
|
||||||
|
'description': f'freq module of {self.name}',
|
||||||
|
'cap': self.name}
|
||||||
|
|
||||||
def parse_reply(self, reply):
|
def parse_reply(self, reply):
|
||||||
if reply.startswith('SI'): # this is an echo
|
if reply.startswith('SI'): # this is an echo
|
||||||
@@ -76,17 +86,17 @@ class Capacitance(HasIO, Pinata, Readable):
|
|||||||
# split() ignores multiple white space
|
# split() ignores multiple white space
|
||||||
reply = reply.replace('=', '= ').replace('>', '> ').split()
|
reply = reply.replace('=', '= ').replace('>', '> ').split()
|
||||||
_, freq, _, _, cap, _, _, loss, lossunit, _, volt = reply[:11]
|
_, freq, _, _, cap, _, _, loss, lossunit, _, volt = reply[:11]
|
||||||
self.freq = freq
|
self.freq = float(freq)
|
||||||
self.voltage = volt
|
self.voltage = float(volt)
|
||||||
if lossunit == 'DS':
|
if lossunit == 'DS':
|
||||||
self.loss = loss
|
self.loss = float(loss)
|
||||||
else: # the unit was wrong, we want DS = tan(delta), not NS = nanoSiemens
|
else: # the unit was wrong, we want DS = tan(delta), not NS = nanoSiemens
|
||||||
reply = self.communicate('UN DS').split() # UN DS returns a reply similar to SI
|
reply = self.communicate('UN DS').split() # UN DS returns a reply similar to SI
|
||||||
try:
|
try:
|
||||||
self.loss = reply[7]
|
self.loss = reply[7]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass # don't worry, loss will be updated next time
|
pass # don't worry, loss will be updated next time
|
||||||
return cap
|
return float(cap)
|
||||||
|
|
||||||
def read_value(self):
|
def read_value(self):
|
||||||
return self.parse_reply(self.communicate('SI')) # SI = single trigger
|
return self.parse_reply(self.communicate('SI')) # SI = single trigger
|
||||||
@@ -126,3 +136,25 @@ class Loss(Readable):
|
|||||||
def read_value(self):
|
def read_value(self):
|
||||||
self.cap.read_value()
|
self.cap.read_value()
|
||||||
return self.cap.loss
|
return self.cap.loss
|
||||||
|
|
||||||
|
|
||||||
|
class Freq(Writable):
|
||||||
|
cap = Attached()
|
||||||
|
value = Parameter('', FloatRange(unit='Hz'), default=0)
|
||||||
|
|
||||||
|
def initModule(self):
|
||||||
|
super().initModule()
|
||||||
|
self.cap.registerCallbacks(self, ['status']) # auto update status
|
||||||
|
|
||||||
|
def update_value(self, _):
|
||||||
|
# value is always changed shortly after freq
|
||||||
|
self.value = self.cap.freq
|
||||||
|
|
||||||
|
@nopoll
|
||||||
|
def read_value(self):
|
||||||
|
self.cap.read_value()
|
||||||
|
return self.cap.freq
|
||||||
|
|
||||||
|
def write_target(self, target):
|
||||||
|
self.cap.write_freq(target)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user