PySerial precision list_port

I want to use pySerial serial.tools.list_ports.comports()to display the available COM ports.

Reading documentation :

The function returns iterability, which gives tuples of three lines:

  • port name, as it can be passed to serial.Serial or serial.serial_for_url ()
  • readable description
  • type of equipment identifier. For instance. May contain VID: PID of USB serial adapters.

I am particularly interested in the third line for finding a specific USB serial adapter with a pair of VID: PID. I would like (ideally) to work on Windows XP and later, Mac OS X and Linux. I tried with pySerial 2.7 on Ubuntu 13.10 and Windows 7 and it works like a charm, but the docs also say:

Also note that these lines are different for different platforms and operating systems, even for the same device.

Note. Support is limited to several operating systems. On some, the system description and equipment identifier will not be available.

Do you have any real experience with these ambiguities? More detailed information? Any non-working example? Variations on equipment identifier strings in different systems?

Thank you so much!

+3
source share
1 answer

I think if you want the counter example not to work as expected, this is 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 the FTDI USB to serial adapter is connected. Expected because here is the function comports():

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]

cygwin, BSD, NetBSD, IRIX, HP-UX, Solaris/SunOS, AIX...

? , pyserial - 2.6, : -)

(2.7) pypi, :

>>> 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']]

, pyserial setup.py . ​​ unix. , VID:PID , , . , , - : vid, pid = sp[2].split(' ')[1].split('=')[-1].split(':') ( , , , ?), , szHardwareID_str = 'USB VID:PID=%s:%s SNR=%s' % (m.group(1), m.group(2), m.group(4)) !)

, , pyserial , : On some systems description and hardware ID will not be available (None)., 'n/a'. , pyserial 2.8: -)

+2

All Articles