Created
October 4, 2012 14:09
-
-
Save hypebeast/3833744 to your computer and use it in GitHub Desktop.
Enumerate serial ports on Windowns. Taken from http://ottawarobotics.org/subversion/Members/andrzej/PYTHON/PyDaq/src/PyDaq/Sandbox/Eli_Benderskys_demos/SerialMon/eblib/utils.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment