Created
September 13, 2016 02:33
-
-
Save arose13/8cfce026bae87a3c18624833657d88ac to your computer and use it in GitHub Desktop.
Find all the connected serial ports (only tested on Linux)
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 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