From 9d9b5b2694913982fe4cc404ca08d4bdbf601563 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Wed, 23 Aug 2023 13:05:18 +0200 Subject: [PATCH] frappy_psi.phytron: further improvements unfortunaely, sometimes communication errors happen. workaround: try several times reading the status Change-Id: I2788c6c9b4145246cdd51c31b246abffee60f93b Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/32032 Tested-by: Jenkins Automated Tests Reviewed-by: Markus Zolliker --- frappy_psi/phytron.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/frappy_psi/phytron.py b/frappy_psi/phytron.py index fdd3039..1705a50 100644 --- a/frappy_psi/phytron.py +++ b/frappy_psi/phytron.py @@ -192,9 +192,17 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable): self.hw_stop() def read_status(self): - sysstatus = self.communicate(f'{self.address:x}SE') - sysstatus = sysstatus[1:4] if self.axis == 'X' else sysstatus[5:8] - status = self.STATUS_MAP.get(sysstatus[1:]) or (ERROR, f'unknown error {sysstatus[1:]}') + for _ in range(3): + sysstatus = self.communicate(f'{self.address:x}SE') + try: + sysstatus = sysstatus[1:4] if self.axis == 'X' else sysstatus[5:8] + status = self.STATUS_MAP[sysstatus[1:]] + except Exception: # can not interprete the reply, probably communication error + self.log.warning('bad status reply %r', sysstatus) + continue + break + else: + status = (ERROR, f'unknown status after 3 tries {sysstatus!r}') self._running = sysstatus[0] != '1' if status[0] == ERROR: self._blocking_error = status[1] @@ -213,7 +221,7 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable): enc = self.read_encoder() else: enc = self.value - if not self._running: # at target + if not self._running: # at target (self._running is updated in self.read_status()) return False diff = abs(self.value - self._intermediate_target) if diff > self._prev_diff and diff > self.encoder_tolerance: