From 558fec9d609a31cf52cf3f97520d4c804308c607 Mon Sep 17 00:00:00 2001 From: Peter Hinch Date: Mon, 30 Nov 2015 15:31:09 +0000 Subject: [PATCH] Fix for issue #7 --- rshell/pyboard.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/rshell/pyboard.py b/rshell/pyboard.py index 92c8d93..d9d4798 100755 --- a/rshell/pyboard.py +++ b/rshell/pyboard.py @@ -123,7 +123,22 @@ def __init__(self, device, baudrate=115200, user='micro', password='python'): self.serial = TelnetToSerial(device, user, password, read_timeout=10) else: import serial - self.serial = serial.Serial(device, baudrate=baudrate, interCharTimeout=1) + done = False + for attempt in range(20): + try: + self.serial = serial.Serial(device, baudrate=baudrate, interCharTimeout=1) + done = True + break + except OSError: + if attempt == 0: + sys.stdout.write('Waiting for pyboard ') + time.sleep(1) + sys.stdout.write('.') + sys.stdout.flush() + print() + if not done: + print("Failed to access device") + sys.exit(1) def close(self): self.serial.close()