When USB CDC ACM device is attached to the system, and user is trying to use comports() to access the description of all com ports in Linux system, IO exception occurs. Here is an example of the IOError Message I get in Fedora 19:
Traceback (most recent call last):
File "/usr/lib/python3.3/site-packages/serial/tools/list_ports_posix.py", line 18, in popen
return subprocess.check_output(argv, stderr=subprocess.STDOUT).strip()
File "/usr/lib64/python3.3/subprocess.py", line 586, in check_output>
raise CalledProcessError(retcode, process.args, output=output)
subprocess.CalledProcessError: Command '['lsusb', '-v', '-s', '3:11']' returned non-zero exit status 1During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.3/site-packages/serial/tools/list_ports_posix.py", line 69, in usb_lsusb_string
desc = popen(['lsusb', '-v', '-s', '%s:%s' % (bus, dev)])
File "/usr/lib/python3.3/site-packages/serial/tools/list_ports_posix.py", line 20, in popen
raise IOError('lsusb failed')
OSError: lsusb failedDuring handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "acceptance_test.py", line 29, in <module>
dumpComPortList()
File "acceptance_test.py", line 26, in dumpComPortList
for port, desc, hwid in sorted(comports()):
File "/usr/lib/python3.3/site-packages/serial/tools/list_ports_posix.py", line 122, in comports
return [(d, describe(d), hwinfo(d)) for d in devices]
File "/usr/lib/python3.3/site-packages/serial/tools/list_ports_posix.py", line 122, in <listcomp>
return [(d, describe(d), hwinfo(d)) for d in devices]
File "/usr/lib/python3.3/site-packages/serial/tools/list_ports_posix.py", line 93, in describe
return usb_lsusb_string(sys_usb)
File "/usr/lib/python3.3/site-packages/serial/tools/list_ports_posix.py", line 80, in usb_lsusb_string
return base
NameError: global name 'base' is not defined</listcomp></module>
After tracing back the errors, the Real Path given by /sys/class/tty/ttyUSB1/device/driver/ttyUSB1 is encoded using busnum-portnum instead of devnum.
Here is the lsusb -t result
/: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/6p, 5000M
/: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/14p, 480M
|-- Port 11: Dev 8, If 0, Class=Vendor Specific Class, Driver=, 480M
|-- Port 11: Dev 8, If 1, Class=Vendor Specific Class, Driver=ftdi_sio, 480M
|-- Port 12: Dev 3, If 0, Class=Hub, Driver=hub/4p, 12M
|-- Port 4: Dev 4, If 0, Class=Hub, Driver=hub/4p, 12M
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
|-- Port 1: Dev 2, If 0, Class=Hub, Driver=hub/8p, 480M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
|-- Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M
and Bus 03, Port 11: Dev 8 is the usb-serial device
The real path of /sys/class/tty/ttyUSB1/device/driver/ttyUSB1 is
sys/devices/pci0000:00/0000:00:14.0/usb3/3-11
As a result, based on list_ports_posix.py, 3-11 is recognized as busNum:devNum and the command lsusb -v -s 3:11 is issued and returned with failure - since the devNum of the device is 8 instead of 11.
Such method to get devNum coded in list_ports_posix.py should be changed.
A suggested method is to cat the "devnum" file under the sys/devices/pci0000:00/0000:00:14.0/usb3/3-11 to get the devnum of corresponding device!
Here is the patch to fix the issue:
Last edit: tinghui.wang 2015-03-24
the current code reads the devnum according to this suggestion, will be fixed in next release