From c97f6cc176057ad8cd6619b878863a866b04dc5c Mon Sep 17 00:00:00 2001 From: Timothy Allen Date: Sat, 10 Oct 2026 09:03:33 +0200 Subject: [PATCH] Handle a JBD read that returns no response collect_data called len() on each response. A port that cannot open returns False or None, so the call raised TypeError and ended the server. Treat each empty or absent response as a failed read. --- bmspy/jbd_bms.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bmspy/jbd_bms.py b/bmspy/jbd_bms.py index 455d497..bcf3732 100644 --- a/bmspy/jbd_bms.py +++ b/bmspy/jbd_bms.py @@ -116,7 +116,8 @@ def collect_data(ser: serial.Serial, debug: int = 0) -> JBDBMS | bool: reqmsg = bytearray([0xDD, 0xA5, 0x03, 0x00, 0xFF, 0xFD, 0x77]) response_03 = requestMessage(ser, reqmsg, debug) - if len(response_03) == 0: + # A port that cannot open returns False or None, not an empty response. + if not response_03: if debug > 0: debugger("collect_data: Error retrieving BMS info. Trying again...") return False @@ -125,7 +126,7 @@ def collect_data(ser: serial.Serial, debug: int = 0) -> JBDBMS | bool: reqmsg = bytearray([0xDD, 0xA5, 0x04, 0x00, 0xFF, 0xFC, 0x77]) response_04 = requestMessage(ser, reqmsg, debug) - if len(response_04) == 0: + if not response_04: if debug > 0: debugger("collect_data: Error retrieving BMS info. Trying again...") return False