0

I want to discover all serial devices on my Windows PC, via a Python script. How can I achieve this properly ?

The ugly way is to try opening COM1, COM2, ..., COM9999 (what is the limit ?), and when an exception is raised, then conclude that no device is there.

user803422
  • 2,636
  • 2
  • 18
  • 36
  • I found [this](http://pyserial.sourceforge.net/pyserial_api.html) – Elazar May 29 '13 at 10:47
  • 1
    and this: http://stackoverflow.com/questions/12090503/listing-available-com-ports-with-python – Elazar May 29 '13 at 10:48
  • These links are interesting. They do not give any answer but refer to other interesting information. I will try something tomorrow... – user803422 May 29 '13 at 19:22

1 Answers1

1

I found an answer that uses the pyserial module, though it is not documented:

import serial.tools.list_ports_windows
devices = serial.tools.list_ports_windows.comports()

and on Linux (though not addressed in the original question):

import serial.tools.list_ports_posix
devices = serial.tools.list_ports_posix.comports()
user803422
  • 2,636
  • 2
  • 18
  • 36