From c2ce0c9cc430fa88b17f23323720348c4ce63b53 Mon Sep 17 00:00:00 2001 From: askiiart Date: Tue, 25 Oct 2022 21:18:29 -0500 Subject: [PATCH] Auto detect port --- Demos/Python/pyserialtransfer_demo.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Demos/Python/pyserialtransfer_demo.py b/Demos/Python/pyserialtransfer_demo.py index f2d70a3..836a3ce 100644 --- a/Demos/Python/pyserialtransfer_demo.py +++ b/Demos/Python/pyserialtransfer_demo.py @@ -1,4 +1,5 @@ import time +from subprocess import getoutput from pySerialTransfer import pySerialTransfer as txfer @@ -9,7 +10,14 @@ try: # On Linux, it will be "/dev/ttyXXX#", like "/dev/ttyACM0" or "/dev/ttyUSB0". I think macOS is the same. # On Windows, it will be "COM#", like "COM3" # --- - port = '/dev/ttyACM2' + port = 'ttyACM' + while True: + ports = getoutput(f'ls /dev | grep {port}').split('\n') + if ports != ['']: + ports.sort() + port = ports[len(ports) - 1] + break + link = txfer.SerialTransfer(port, 115200, timeout=.1) link.open()