Skip to content

Instantly share code, notes, and snippets.

@sw
Created September 27, 2011 06:09
Show Gist options
  • Save sw/1244446 to your computer and use it in GitHub Desktop.
Save sw/1244446 to your computer and use it in GitHub Desktop.
python snippet to enumerate serial ports on Windows
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