From 3c3f487e1e62febcdc56534b717f14840bda1352 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Fri, 13 Jul 2012 02:15:45 -0400 Subject: Add win-list-com-ports.py. Utility for listing COM ports available on the system. Taken from Eli Bendersky. Signed-off-by: Marti Bolivar --- support/scripts/win-list-com-ports.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 support/scripts/win-list-com-ports.py (limited to 'support') diff --git a/support/scripts/win-list-com-ports.py b/support/scripts/win-list-com-ports.py new file mode 100644 index 0000000..3e6ecb8 --- /dev/null +++ b/support/scripts/win-list-com-ports.py @@ -0,0 +1,29 @@ +# Windows program for listing COM (serial) ports. +# +# enumerate_serial_ports() is by Eli Bendersky: +# +# http://eli.thegreenplace.net/2009/07/31/listing-all-serial-ports-on-windows-with-python/ + +import _winreg as winreg +import itertools + +def enumerate_serial_ports(): + """ Uses the Win32 registry to return an + iterator of serial (COM) ports + existing on this computer. + """ + path = 'HARDWARE\\DEVICEMAP\\SERIALCOMM' + try: + key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path) + except WindowsError: + raise IterationError + + for i in itertools.count(): + try: + val = winreg.EnumValue(key, i) + yield str(val[1]) + except EnvironmentError: + break + +for com in enumerate_serial_ports(): + print com -- cgit v1.2.3