Created
October 13, 2019 13:10
-
-
Save bart02/e3949d2b3498c31a72d475b8f2290f7d to your computer and use it in GitHub Desktop.
Function for searching the arduino port
This file contains hidden or 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 serial | |
| def search(): | |
| found = False | |
| for j in range(3): | |
| for i in range(64): | |
| try: | |
| if j == 0: | |
| port = "/dev/ttyACM" + str(i) | |
| elif j == 1: | |
| port = "/dev/ttyUSB" + str(i) | |
| elif j == 2: | |
| port = "COM" + str(i) | |
| ser = serial.Serial(port) | |
| ser.close() | |
| found = True | |
| break | |
| except serial.serialutil.SerialException: | |
| pass | |
| if found: | |
| return port | |
| break | |
| if not found: | |
| raise NameError("Ports not found") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment