Pyserial List Serial Ports

2020. 12. 13. 05:01카테고리 없음



Active1 year, 1 month ago
  1. Virtual Serial Ports
  2. Pyserial List Serial Ports For Sale
  3. Pyserial List Serial Ports List
  4. Pyserial Serial.tools.list_ports.comports()

I want to use pySerial's serial.tools.list_ports.comports() to list available COM ports.

Reading the documentation: Slysoft-clonecd software.

I'm looking for a robust way to list the available serial (COM) ports on a Windows machine. Online lie detector test voice. There's this post about using WMI, but I would like something less.NET specific - I want to get the list of ports in a Python or a C program, without.NET. I currently know of two other approaches: Reading the information in the HARDWAREDEVICEMAPSERIALCOMM registry key.

The function returns an iterable that yields tuples of three strings:

  • port name as it can be passed to serial.Serial or serial.serial_for_url()
  • description in human readable form
  • sort of hardware ID. E.g. may contain VID:PID of USB-serial adapters.
  • Port name, description and hardware ID are searched (case insensitive). The function returns an iterable that contains the same tuples that comport generates, but includes only those entries that match the regexp. Class serial.tools.listports.ListPortInfo¶ This object holds information about a serial port.
  • Listports does not seem to find all the available com ports, because I have a USB serial device that does not show up using the listports generator, yet realterm finds it and puts it in the list of selectable ports without any problem.

I'm particulary interested in the third string to search for a specific USB-serial adapter with a VID:PID pair. I would like it (ideally) to work in Windows XP and later, Mac OS X, and Linux. I've tried with pySerial 2.7 in Ubuntu 13.10 and Windows 7 and works like a charm, but the docs also say:

List

Also note that the reported strings are different across platforms and operating systems, even for the same device.

Note: Support is limited to a number of operating systems. On some systems description and hardware ID will not be available.

Do you have any real-world experience with respect these ambiguities? More detailed info? Any non-working example? Variations on the hardware ID strings across systems?

Thanks a lot!

Usb serial ports
Diego Herranz
Diego HerranzDiego Herranz
1,7622 gold badges12 silver badges31 bronze badges

2 Answers

I guess if you want a counter-example of it working not as expected, here's what I get:

where a FTDI USB-Serial adapter is plugged in. Which is expectable, because here's the comports() function:

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:

Virtual Serial Ports

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 :-)

zmozmo
21.1k2 gold badges40 silver badges74 bronze badges

It's been some time since my original question, but current versions of pyserial (3.0+, I believe) have solved this in a neat way. No more clever parsing.

Pyserial List Serial Ports For Sale

serial.tools.list_ports.comports(..) now returns a list containing ListPortInfo objects.

ListPortInfo objects contain vid and pid attributes (integer) as well as other useful USB-related attributes (see docs) which 'are all None if it is not an USB device (or the platform does not support extended info)' and this seems to be supported on the main 3 platforms ('Under Linux, OSX and Windows, extended information will be available for USB devices').

JavaScript is a programming language that adds interactivity to your website (for example games, responses when buttons are pressed or data is entered in forms, dynamic styling, and animation). Javascript programs examples with output pdf. This article helps you get started with this exciting language and gives you an idea of what is possible. What is JavaScript, really?('JS' for short) is a full-fledged that, when applied to an document, can provide dynamic interactivity on websites. It was invented by Brendan Eich, co-founder of the Mozilla project, the Mozilla Foundation, and the Mozilla Corporation.JavaScript is incredibly versatile.

So you can do something like the following:

Diego HerranzDiego Herranz

Pyserial List Serial Ports List

1,7622 gold badges12 silver badges31 bronze badges

Pyserial Serial.tools.list_ports.comports()

Not the answer you're looking for? Browse other questions tagged pythonserial-portpyserial or ask your own question.