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
This commit is contained in:
Gina Häußge 2017-10-11 16:19:37 +02:00
parent d1fdbd5080
commit 4093995ba0

View file

@ -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