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()