aboutsummaryrefslogtreecommitdiffstats
path: root/support
diff options
context:
space:
mode:
Diffstat (limited to 'support')
-rw-r--r--support/scripts/win-list-com-ports.py29
1 files changed, 29 insertions, 0 deletions
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