I guess if you want a counter-example of it working not as expected, here's what I get:
>>> serial.tools.list_ports.comports()
[('/dev/tty.Bluetooth-Incoming-Port', '/dev/tty.Bluetooth-Incoming-Port', '/dev/tty.Bluetooth-Incoming-Port'), ('/dev/tty.Bluetooth-Modem', '/dev/tty.Bluetooth-Modem', '/dev/tty.Bluetooth-Modem'), ('/dev/tty.usbserial-A1024XBO', '/dev/tty.usbserial-A1024XBO', '/dev/tty.usbserial-A1024XBO')]
where a FTDI USB-Serial adapter is plugged in. Which is expectable, because here's the comports()
function:
def comports():
"""scan for available ports. return a list of device names."""
devices = glob.glob('/dev/tty.*')
return [(d, d, d) for d in devices]
which is the same for cygwin, BSD, NetBSD, IRIX, HP-UX, Solaris/SunOS, AIX…
How come that result can happen? Well, because my pyserial is version 2.6, which is only six months old :-)
After upgrading to latest version (2.7) from pypi, here's what I get:
>>> serial.tools.list_ports.comports()
[['/dev/cu.Bluetooth-Incoming-Port', 'n/a', 'n/a'], ['/dev/cu.Bluetooth-Modem', 'n/a', 'n/a'], ['/dev/cu.usbserial-A1024XBO', 'FT232R USB UART', 'USB VID:PID=403:6001 SNR=A1024XBO']]
so basically, add a version check to the latest version of pyserial
in your setup.py, or you may get problems. Though support is still not added for other unix flavors. It looks like the VID:PID
string is handled directly by parsing OS specific stuff to make that string generic enough. So basically I guess you can safely get it with something like : vid, pid = sp[2].split(' ')[1].split('=')[-1].split(':')
(which is quite stupid, why parse values to build a string that has to be parsed again afterwards?!, I mean they do szHardwareID_str = 'USB VID:PID=%s:%s SNR=%s' % (m.group(1), m.group(2), m.group(4))
we couldn't be happier with just a tuple!)
And finally, pyserial looks inconsistent with its documentation, as it says: On some systems description and hardware ID will not be available (None).
, whereas it does really return 'n/a'
. I guess that will be fixed in pyserial 2.8 :-)