From 27778e80f544cefc4b746b82c3176a8f5072d9c7 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Tue, 10 Jun 2025 16:49:15 +0200 Subject: [PATCH] SEA: let tt.value be the sample temperature when dblctrl is on for this tt has to be a frappy_psi.sea.LscDrivable Change-Id: Ic452b39237d31a7765bc8b2f22a12c2f454fe7da --- frappy_psi/sea.py | 65 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/frappy_psi/sea.py b/frappy_psi/sea.py index 10aa4ad..af84181 100644 --- a/frappy_psi/sea.py +++ b/frappy_psi/sea.py @@ -667,18 +667,22 @@ class SeaModule(Module): path2param.setdefault(hdbpath, []).append((name, key)) attributes[key] = pobj - def rfunc(self, cmd=f'hval {base}/{path}'): - reply = self.io.query(cmd, True) - try: - reply = float(reply) - except ValueError: - pass - # an updateEvent will be handled before above returns - return reply - - rfunc.poll = False if key != 'status' and key is not None: - attributes['read_' + key] = rfunc + rfunc = getattr(cls, f'read_{key}', None) + # do not override existing read method + if rfunc is None: + + def rfunc(self, cmd=f'hval {base}/{path}'): + reply = self.io.query(cmd, True) + try: + reply = float(reply) + except ValueError: + pass + # an updateEvent will be handled before above returns + return reply + + rfunc.poll = False + attributes['read_' + key] = rfunc if not readonly and key: @@ -722,9 +726,9 @@ class SeaModule(Module): if sublist is None: return False if len(sub) > 1 or 'kids' in paramdesc: - # avoid params from subtrees + # avoid params from subtrees return False - # this is a top paramerter without kids + # this is a top parameter without kids sublist.append(paramdesc) return True @@ -856,9 +860,20 @@ class SeaDrivable(SeaReadable, Drivable): class LscDrivable(SeaDrivable): def __new__(cls, name, logger, cfgdict, srv): - cfgdict['rel_paths'] = [pop_cfg(cfgdict, 'sensor_path', 'tm'), '.', - pop_cfg(cfgdict, 'set_path', 'set'), 'dblctrl'] - return super().__new__(cls, name, logger, cfgdict, srv) + sensor_path = pop_cfg(cfgdict, 'sensor_path', 'tm') + set_path = pop_cfg(cfgdict, 'set_path', 'set') + cfgdict['rel_paths'] = ['.', sensor_path, set_path , 'dblctrl'] + mobj = super().__new__(cls, name, logger, cfgdict, srv) + mobj._sensor_path = sensor_path + + def ufunc(value, timestamp, readerror, self=mobj): + if not self.dblctrl: + self.update_value(value, timestamp, readerror) + self.announceUpdate(self._sensor_path, value, readerror, timestamp) + + setattr(mobj, f'update_{sensor_path}', ufunc) + mobj._read_value_error = False + return mobj @classmethod def paramFilter(cls, result, paramdesc): @@ -869,3 +884,21 @@ class LscDrivable(SeaDrivable): result['.'].append(paramdesc) return True return False + + def update_value(self, value, timestamp, readerror): + self._read_value_error = readerror + if self.dblctrl and not readerror: + super().update_value(value, timestamp, readerror) + + def read_value(self): + if self.io.syncio: + try: + if self.dblctrl and not self._read_value_error: + reply = self.io.query('hval tt', True) + else: + reply = self.io.query(f'hval tt/{self.rel_paths[1]}', True) + except Exception as e: + print(e) + # an updateEvent will be handled before above returns + return float(reply) + return self.value