Skip to content

Instantly share code, notes, and snippets.

@arose13
Created September 13, 2016 02:33
Show Gist options
  • Save arose13/8cfce026bae87a3c18624833657d88ac to your computer and use it in GitHub Desktop.
Save arose13/8cfce026bae87a3c18624833657d88ac to your computer and use it in GitHub Desktop.
Find all the connected serial ports (only tested on Linux)
import glob
import serial
def serial_ports():
ports = glob.glob('/dev/tty[A-Za-z]*')
working_ports = []
for port in ports:
try:
ser = serial.Serial(port)
ser.close()
working_ports.append(port)
except (OSError, serial.SerialException):
pass
return working_ports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment