From 431f665cf2491eee526c792e9217cb36bc377dce Mon Sep 17 00:00:00 2001 From: askiiart Date: Thu, 14 Nov 2024 08:38:48 -0600 Subject: [PATCH] make the code slightly less terrible --- Python/tx_loop.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Python/tx_loop.py b/Python/tx_loop.py index 1cd5931..7c8cf61 100644 --- a/Python/tx_loop.py +++ b/Python/tx_loop.py @@ -2,6 +2,7 @@ import GPUtil import time from pySerialTransfer import pySerialTransfer as txfer from subprocess import getoutput +from glob import glob try: # --- @@ -13,13 +14,12 @@ try: port = 'ttyACM' while True: - ports = getoutput(f'ls /dev | grep {port}').split('\n') - if ports != ['']: - ports.sort() - port = ports[len(ports) - 1] + try: + port = glob(f'ls /dev/{port}*')[-] break - print('Waiting for Arduino...') - time.sleep(3) + except IndexError: + print('Waiting for Arduino...') + time.sleep(3) link = txfer.SerialTransfer(port, 115200, timeout=.1)