getport.py 294 Bytes
Newer Older
1
2
3
4
5
6
7
8
import os
ports = [x for x in os.listdir("/dev") if x.startswith("ttyUSB")
                                       or x.startswith("ttyACM")]
if ports and isinstance(ports[0], str):
    print(ports[0])
else:
    print("Error: Unable to find a ttyUSB/ttyACM serial port")
    raise SystemExit(1)