Skip to content

Instantly share code, notes, and snippets.

@mba7
Created June 18, 2014 14:20
Show Gist options
  • Save mba7/63eff49085600d6b8b52 to your computer and use it in GitHub Desktop.
Save mba7/63eff49085600d6b8b52 to your computer and use it in GitHub Desktop.
enumerate the availables serial ports using pyserial
def enumerate_serial_ports():
"""
Purpose: scan for available ports
Return: return a list containing the names of
the availables serial ports
"""
outAvailablePorts = []
for i in range(256):
try:
s = serial.Serial(i)
outAvailablePorts.append(s.portstr)
s.close()
except serial.SerialException:
pass
return outAvailablePorts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment