phytron: fix warning on repeated comm. error

log only a warning when several retries ware successful

Change-Id: I2f1dfba920b0841914da82229820bcdd4b97c6e9
This commit is contained in:
zolliker 2022-09-21 11:35:42 +02:00
parent 9f656546df
commit e4aa2149f7

View File

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