Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rshell throws exception if started just after Pyboard plugged in #7

Open
peterhinch opened this issue Jul 10, 2015 · 4 comments
Open

Comments

@peterhinch
Copy link

This is arguably trivial, but if /dev/ttyACM0 has only just been instantiated when rshell is started the following occurs:

$ rshell
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 275, in open
    self.fd = os.open(self.portstr, os.O_RDWR|os.O_NOCTTY|os.O_NONBLOCK)
OSError: [Errno 16] Device or resource busy: '/dev/ttyACM0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/mnt/qnap2/python/rshell/rshell.py", line 1434, in <module>
    main()
  File "/mnt/qnap2/python/rshell/rshell.py", line 1355, in main
    pyb = pyboard.Pyboard(args.port, baudrate=args.baud)
  File "/mnt/qnap2/python/rshell/pyboard.py", line 45, in __init__
    self.serial = serial.Serial(serial_device, baudrate=baudrate, interCharTimeout=1)
  File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 261, in __init__
    self.open()
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 278, in open
    raise SerialException("could not open port %s: %s" % (self._port, msg))
serial.serialutil.SerialException: could not open port /dev/ttyACM0: [Errno 16] Device or resource busy: '/dev/ttyACM0'
@peterhinch
Copy link
Author

A further observation. This effect is PC/distro/timing dependent. On my laptop, if I start rshell and then plug in the pyboard, it initially reports that it is waiting for /dev/ttyACM0 and then throws the exception. On my desktop this scenario doesn't produce the fault which only occurs if I start rshell soon after plugging in the Pyboard.

@dhylands
Copy link
Owner

@peterhinch If you're running linux, it would be interesting to see if usb-ser-mon.py behaves the same way. usb-ser-mon.py hooks in with udev to detect when serial ports come and go.
https://github.com/dhylands/usb-ser-mon It needs pyudev to be installed.

@peterhinch
Copy link
Author

I started usb-ser-mon with the Pyboard connected (it had been connected for some time) and it detected it. I then unplugged the Pyboard and plugged it back in again. This was the outcome of the sequence described.

$ ./usb-ser-mon.py 
USB Serial device with vendor 'Micro_Python' serial '000000000011' connected @/dev/ttyACM0
Use Control-X to exit.
USB Serial device @/dev/ttyACM0 disconnected.

Waiting for USB Serial Device ...
USB Serial device with vendor 'Micro_Python' serial '000000000011' connected @/dev/ttyACM0
Use Control-X to exit.
Traceback (most recent call last):
                                    File "./usb-ser-mon.py", line 293, in main
                                                                                  debug=args.debug, echo=args.echo)
                                                                                                                     File "./usb-ser-mon.py", line 148, in usb_serial_mon
                                                       log(data, end='')
                                                                          File "./usb-ser-mon.py", line 28, in log
                                                                                                                      if str[-1] == '\r':
                   IndexError: string index out of range
                                                        [adminpete@axolotl]: ~/qnap/python/usb_ser_mon/usb-ser-mon
$ 

@dhylands
Copy link
Owner

ok - I'll have to fix that - that looks like a logic error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants