From 03ae83dbbc3e9bff4a55b0cc71134b32e665fe99 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Wed, 22 Oct 2025 09:15:48 +0200 Subject: [PATCH] frappy_psi.ah2700: fixes --- frappy_psi/ah2700.py | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/frappy_psi/ah2700.py b/frappy_psi/ah2700.py index 27f430f9..53edbd05 100644 --- a/frappy_psi/ah2700.py +++ b/frappy_psi/ah2700.py @@ -29,7 +29,7 @@ an empty name """ from frappy.core import FloatRange, HasIO, Parameter, Readable, StringIO, nopoll, \ - Attached, Property, StringType + Attached, Property, StringType, Writable from frappy.dynamic import Pinata @@ -47,6 +47,11 @@ class Capacitance(HasIO, Pinata, Readable): configure '' to disable the creation of the loss module ''', StringType(), default='$_loss') + freq_name = Property('''name of freq module + + default: not created + ''', + StringType(), default='') ioClass = Ah2700IO loss = 0 # not a parameter @@ -59,6 +64,11 @@ class Capacitance(HasIO, Pinata, Readable): 'cls': Loss, 'description': f'loss value of {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): if reply.startswith('SI'): # this is an echo @@ -76,17 +86,17 @@ class Capacitance(HasIO, Pinata, Readable): # split() ignores multiple white space reply = reply.replace('=', '= ').replace('>', '> ').split() _, freq, _, _, cap, _, _, loss, lossunit, _, volt = reply[:11] - self.freq = freq - self.voltage = volt + self.freq = float(freq) + self.voltage = float(volt) if lossunit == 'DS': - self.loss = loss + self.loss = float(loss) 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 try: self.loss = reply[7] except IndexError: pass # don't worry, loss will be updated next time - return cap + return float(cap) def read_value(self): return self.parse_reply(self.communicate('SI')) # SI = single trigger @@ -126,3 +136,25 @@ class Loss(Readable): def read_value(self): self.cap.read_value() 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) +