aboutsummaryrefslogtreecommitdiffstats
path: root/support
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@lozenge.(none)>2012-07-13 02:15:45 -0400
committerMarti Bolivar <mbolivar@lozenge.(none)>2012-07-13 02:15:45 -0400
commit3c3f487e1e62febcdc56534b717f14840bda1352 (patch)
tree7fd9bcaab9bc9cdbce387546eeb73e4240a8cb57 /support
parent94ddccd06c20cc8e7fef34fe53d7b550b64d65da (diff)
downloadlibrambutan-3c3f487e1e62febcdc56534b717f14840bda1352.tar.gz
librambutan-3c3f487e1e62febcdc56534b717f14840bda1352.zip
Add win-list-com-ports.py.
Utility for listing COM ports available on the system. Taken from Eli Bendersky. Signed-off-by: Marti Bolivar <mbolivar@lozenge.(none)>
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