some fixes

This commit is contained in:
Your Name
2026-03-10 15:48:57 +03:00
parent 32fb12a2c2
commit ecdad1b583
2 changed files with 15 additions and 26 deletions

View File

@ -13,31 +13,16 @@ WAIT_AFTER_SEND = 0.15 # Wait after sending command before requesting input (s)
def create_port_connection():
prt = None
print()
ports = [port for port, _, _ in sorted(cmd.list_ports.comports())]
# Linux-only preference: use USB UART ports first.
usb_ports = [port for port in ports if "USB" in port]
if usb_ports:
ports = usb_ports
for port in ports:
for port, _, _ in sorted(cmd.list_ports.comports()):
try:
print("PORT:", port)
prt = cmd.setup_port_connection(port=port, baudrate=115200, timeout_sec=1)
cmd.open_port(prt)
reset_port_settings(prt)
return prt
except Exception:
if prt is not None:
try:
prt.close()
except Exception:
pass
except:
prt.close()
continue
return None
break
return prt
def _print_state_reply(state_bytes):
@ -51,9 +36,13 @@ def _print_state_reply(state_bytes):
def reset_port_settings(prt):
# Reset port settings and check status
cmd.send_DEFAULT_ENABLE(prt)
time.sleep(WAIT_AFTER_SEND)
return _print_state_reply(cmd.get_STATE(prt))
status = cmd.get_STATE(prt).hex()
if status is not None:
print("Received: STATE. State status:", cmd.decode_STATE(status), "(" + cmd.flipfour(status) + ")")
print("")
def request_state(prt):