some fixes
This commit is contained in:
@ -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):
|
||||
|
||||
Reference in New Issue
Block a user