Go Down

Topic: Python on Mac: "resource busy" (Read 604 times) previous topic - next topic


Nov 21, 2019, 09:36 am Last Edit: Nov 21, 2019, 09:38 am by westfw
Huh.  Can anyone explain why Python's pyserial library fails to open /dev/tty.xxx, but works fine on /dev/cu.xxxx ?  (yes, I'm sure that nothing else is using the tty...)

Python 3.6.5 |Anaconda, Inc.| (default, Apr 26 2018, 08:42:37)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> con = serial.Serial("/dev/tty.usbmodem3221")
Traceback (most recent call last):
  File "/Volumes/MacOS/HD-Users/BillW/anaconda3/lib/python3.6/site-packages/serial/serialposix.py", line 265, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
OSError: [Errno 16] Resource busy: '/dev/tty.usbmodem3221'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Volumes/MacOS/HD-Users/BillW/anaconda3/lib/python3.6/site-packages/serial/serialutil.py", line 240, in __init__
  File "/Volumes/MacOS/HD-Users/BillW/anaconda3/lib/python3.6/site-packages/serial/serialposix.py", line 268, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))

serial.serialutil.SerialException: [Errno 16] could not open port /dev/tty.usbmodem3221: [Errno 16] Resource busy: '/dev/tty.usbmodem3221'

>>> con = serial.Serial("/dev/cu.usbmodem3221")

>>> print(con)
Serial<id=0x105d3fef0, open=True>(port='/dev/cu.usbmodem3221', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False)

There are people who have had similar problems on stack overflow and similar, but no solutions (except for the cases where the tty WAS actually in use by something else.)

Go Up