diff --git a/secop_psi/phytron.py b/secop_psi/phytron.py index 614814d..66899e5 100644 --- a/secop_psi/phytron.py +++ b/secop_psi/phytron.py @@ -35,7 +35,9 @@ class PhytronIO(StringIO): identification = [('0IVR', 'MCC Minilog .*')] def communicate(self, command): - for ntry in range(5, 0, -1): + ntry = 5 + warn = None + for itry in range(ntry): try: _, _, reply = super().communicate('\x02' + command).partition('\x02') if reply[0] == '\x06': # ACK @@ -43,9 +45,12 @@ class PhytronIO(StringIO): raise CommunicationFailedError('missing ACK %r (cmd: %r)' % (reply, command)) except Exception as e: - if ntry == 1: + if itry < ntry - 1: + warn = e + else: raise - self.log.warning('%s - retry', e) + if warn: + self.log.warning('needed %d retries after %r', itry, warn) return reply[1:]