Created
September 27, 2011 06:09
-
-
Save sw/1244446 to your computer and use it in GitHub Desktop.
python snippet to enumerate serial ports on Windows
This file contains 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
import itertools | |
import _winreg as winreg | |
def enumerate_serial_ports(): | |
path = 'HARDWARE\\DEVICEMAP\\SERIALCOMM' | |
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path) | |
ports = [] | |
for i in itertools.count(): | |
try: | |
val = winreg.EnumValue(key, i) | |
ports.append(str(val[1])) | |
except EnvironmentError: | |
break | |
return sorted(ports) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment