From fa5d5654f86124a3721cc36e2b28bca61b0c27ac Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Wed, 13 Sep 2023 18:11:13 +0200 Subject: [PATCH] phytron.py: improve status better analysis of hardware status code Change-Id: I667b443649db43ff3e572e0a50685aabc9ba2ca2 Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/32165 Tested-by: Jenkins Automated Tests Reviewed-by: Markus Zolliker --- frappy_psi/phytron.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/frappy_psi/phytron.py b/frappy_psi/phytron.py index 1705a50..244fc7f 100644 --- a/frappy_psi/phytron.py +++ b/frappy_psi/phytron.py @@ -32,6 +32,7 @@ from frappy.core import Done, Command, EnumType, FloatRange, IntRange, \ from frappy.errors import CommunicationFailedError, HardwareError from frappy.features import HasOffset from frappy.states import HasStates, status_code, Retry +from frappy.lib import formatStatusBits class PhytronIO(StringIO): @@ -88,15 +89,8 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable): _prev_diff = 0 # for checking progress _intermediate_target = 0 _stopped_at = 0 - - STATUS_MAP = { - '08': (IDLE, ''), - '01': (ERROR, 'power stage failure'), - '02': (ERROR, 'power too low'), - '04': (ERROR, 'power stage over temperature'), - '07': (ERROR, 'no power stage'), - '80': (ERROR, 'encoder failure'), - } + status_bits = ['power stage error', 'undervoltage', 'overtemperature', 'active', + 'lower switch active', 'upper switch active', 'step failure', 'encoder error'] def get(self, cmd): return self.communicate(f'{self.address:x}{self.axis}{cmd}') @@ -196,14 +190,19 @@ class Motor(HasOffset, HasStates, PersistentMixin, HasIO, Drivable): 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 + hexstatus = int(sysstatus, base=16) + status_items = formatStatusBits(hexstatus & 0xf7, self.status_bits) + if status_items: + status = ERROR, ', '.join(status_items) + else: + status = IDLE, '' + except TimeoutError: # 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' + self._running = (hexstatus & 0x100) == 0 if status[0] == ERROR: self._blocking_error = status[1] return status