From 4093995ba09024882acd2d0ebf05d5068f044fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 11 Oct 2017 16:19:37 +0200 Subject: [PATCH] STK500v2: Retries for reading from serial This would normally not fly at all but we give it a pass here since we only use that module for auto detection anyhow (and probably not for much longer since that approach is simply too error prone). Adapted from https://github.com/foosel/OctoPrint/issues/2138#issuecomment-334117910 by @dtynan. Solves #2138 until I come up with something better --- src/octoprint/util/avr_isp/stk500v2.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/octoprint/util/avr_isp/stk500v2.py b/src/octoprint/util/avr_isp/stk500v2.py index 0fe59fe0..41561c4a 100644 --- a/src/octoprint/util/avr_isp/stk500v2.py +++ b/src/octoprint/util/avr_isp/stk500v2.py @@ -111,8 +111,11 @@ class Stk500v2(ispBase.IspBase): state = 'Start' checksum = 0 while True: - s = self.serial.read() - if len(s) < 1: + for _ in range(0, 5): + s = self.serial.read() + if len(s) > 0: + break + else: raise ispBase.IspError("Timeout") b = struct.unpack(">B", s)[0] checksum ^= b