Skip to content

Instantly share code, notes, and snippets.

@hypebeast
Created October 4, 2012 14:09
Show Gist options
  • Save hypebeast/3833744 to your computer and use it in GitHub Desktop.
Save hypebeast/3833744 to your computer and use it in GitHub Desktop.
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