Skip to content

Commit d1be92e

Browse files
committed
Handle busy serial port gracefully in RS-485 discovery
1 parent ead1e2b commit d1be92e

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

‎scripts/discover-rs485.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def probe_jk_bms(port: str, baud: int, timeout: float = 1.0) -> bool:
8080

8181
found = False
8282
try:
83+
dev.reset_input_buffer()
8384
for req_name, request in [("standard", STATUS_REQUEST), ("fallback", STATUS_REQUEST_FALLBACK)]:
8485
dev.reset_input_buffer()
8586
dev.write(_append_checksum(bytearray(request)))
@@ -98,6 +99,8 @@ def probe_jk_bms(port: str, baud: int, timeout: float = 1.0) -> bool:
9899
found = True
99100
else:
100101
print(f" [{baud}] JK BMS parse failed")
102+
except serial.SerialException as exc:
103+
print(f" [{baud}] Serial error while probing JK BMS: {exc}")
101104
finally:
102105
dev.close()
103106

0 commit comments

Comments
 (0)