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