From 2201af7af18d98e4a9a714b6c8291276323de2bb Mon Sep 17 00:00:00 2001 From: Anik Stark Date: Wed, 11 Mar 2026 09:46:56 +0100 Subject: [PATCH] frappy_psi.ccu4: add timing in Valve class --- frappy_psi/ccu4.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/frappy_psi/ccu4.py b/frappy_psi/ccu4.py index 511d97f0..196a74c6 100644 --- a/frappy_psi/ccu4.py +++ b/frappy_psi/ccu4.py @@ -140,14 +140,18 @@ class Valve(Base, Writable): _query_state = None def write_target(self, target): + self._set_time = time.time() if target: self.command(**self._open_command) else: self.command(**self._close_command) + self.value = target def read_status(self): state = int(self.command(**self._query_state)) - self.value, status = self.STATE_MAP[state] + value, status = self.STATE_MAP[state] + if time.time() > self._set_time + 2: + self.value = value return status @@ -800,3 +804,26 @@ class NeedleValveFlow(HasStates, Base, Drivable): self.log.debug('before %g pulse %g, flowstep %g', sm.flow_before, sm.open_pulse, sm.last[-1] - sm.flow_before) self.close() return self.final_status(IDLE, '') + + +class MotorValve(Base, Drivable): + + STATUS = {'1': (BUSY, 'opening'), + '2': (BUSY, 'closing'), + '3': (IDLE, 'opened'), + '4': (IDLE, 'closed'), + '5': (ERROR, 'no motor'), + } + + value = Parameter('value', datatyp=BoolType()) + target = Parameter('target', datatyp=BoolType(), readonly=False) + + def write_target(self, target): + cmd = 1 + if target == 0: + cmd = -1 + self.communicate(f'mp{60 * cmd}') + + def read_status(self): + status = self.communicate('fm') + return self.STATUS.get(status, (ERROR, f'undefined status: {status}'))