How can I enumerate (list) serial ports?

Tim Golden mail at timgolden.me.uk
Thu Jun 18 02:20:42 EDT 2009


Jason wrote:
> Hi,
> 
> I'm developing an application to talk to a device over a serial port.
> I'm trying my hardest to keep it cross platform, so I was using
> pySerial for the serial communications. But I can't see a pythonic,
> cross-platform way to enumerate serial ports on a machine.

As with many other such issues, instant cross-platformability
is likely to be rare. I admin I haven't looked at pySerial
but I imagine that, behind the scenes, it's doing some sort
of conditional imports according to platform. I imagine you'd
have to do something similar to get a list of port names.

On Windows, WMI can give you what you want. Look at the
Win32_SerialPort class. Hopefully, someone else can help
for other platforms.

TJG





More information about the Python-list mailing list