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.
This commit is contained in:
+3
-2
@@ -116,7 +116,8 @@ def collect_data(ser: serial.Serial, debug: int = 0) -> JBDBMS | bool:
|
|||||||
reqmsg = bytearray([0xDD, 0xA5, 0x03, 0x00, 0xFF, 0xFD, 0x77])
|
reqmsg = bytearray([0xDD, 0xA5, 0x03, 0x00, 0xFF, 0xFD, 0x77])
|
||||||
response_03 = requestMessage(ser, reqmsg, debug)
|
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:
|
if debug > 0:
|
||||||
debugger("collect_data: Error retrieving BMS info. Trying again...")
|
debugger("collect_data: Error retrieving BMS info. Trying again...")
|
||||||
return False
|
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])
|
reqmsg = bytearray([0xDD, 0xA5, 0x04, 0x00, 0xFF, 0xFC, 0x77])
|
||||||
response_04 = requestMessage(ser, reqmsg, debug)
|
response_04 = requestMessage(ser, reqmsg, debug)
|
||||||
|
|
||||||
if len(response_04) == 0:
|
if not response_04:
|
||||||
if debug > 0:
|
if debug > 0:
|
||||||
debugger("collect_data: Error retrieving BMS info. Trying again...")
|
debugger("collect_data: Error retrieving BMS info. Trying again...")
|
||||||
return False
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user