dhylands / upy-shell

MicroPython shell
MIT License
37 stars 9 forks source link

rshell.py nowait replaced by wait (seconds). Requires pyboard.py dated 8th Dec … #13

Open peterhinch opened 8 years ago

peterhinch commented 8 years ago

This is an interim fix to the issue of the behaviour in the case where the pyboard is not ready when rshell is started. If pyboard.py fails to connect in time, rshell prints a message and issues exit(1). I appreciate that your preferred approach is to raise a DeviceError. However if I do that it attempts to autoconnect which then throws an exception and hangs. Until that's fixed it seemed cleanest to quit. Here is the outcome with a non-ready Pyboard using DeviceErrror

[adminpete@axolotl]: ~/upy-shell
$ rshell
Connecting to /dev/pyboard ...
failed to access /dev/pyboard
Welcome to rshell. Use Control-D to exit.

No MicroPython boards connected - use the connect command to add one

/home/adminpete/upy-shell> autoconnect: /dev/ttyACM0 action: add
Connecting to /dev/ttyACM0 ...
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "/mnt/qnap2/python/rshell/rshell.py", line 204, in autoconnect_thread
    connect_serial(usb_dev.device_node)
  File "/mnt/qnap2/python/rshell/rshell.py", line 980, in connect_serial
    dev = DeviceSerial(port, baud, wait)
  File "/mnt/qnap2/python/rshell/rshell.py", line 1181, in __init__
    Device.__init__(self, pyb)
  File "/mnt/qnap2/python/rshell/rshell.py", line 1024, in __init__
    self.sync_time()
  File "/mnt/qnap2/python/rshell/rshell.py", line 1112, in sync_time
    now.tm_hour, now.tm_min, now.tm_sec, 0))
  File "/mnt/qnap2/python/rshell/rshell.py", line 1085, in remote
    output, _ = self.pyb.follow(timeout=10)
  File "/mnt/qnap2/python/rshell/pyboard.py", line 197, in follow
    data = self.read_until(1, b'\x04', timeout=timeout, data_consumer=data_consumer)
  File "/mnt/qnap2/python/rshell/pyboard.py", line 151, in read_until
    data = self.serial.read(min_num_bytes)
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 453, in read
    buf = os.read(self.fd, size-len(read))
BlockingIOError: [Errno 11] Resource temporarily unavailable

Traceback (most recent call last):
  File "/mnt/qnap2/python/rshell/rshell.py", line 2213, in <module>
    main()
  File "/mnt/qnap2/python/rshell/rshell.py", line 2210, in main
    shell.cmdloop(cmd_line)
  File "/mnt/qnap2/python/rshell/rshell.py", line 1284, in cmdloop
    cmd.Cmd.cmdloop(self)
  File "/usr/lib/python3.4/cmd.py", line 126, in cmdloop
    line = input(self.prompt)
KeyboardInterrupt
[adminpete@axolotl]: ~/upy-shell

I have

alias rshell='/mnt/qnap2/python/rshell/rshell.py -p /dev/pyboard'