Catch struct unpack error

This commit is contained in:
Odd Stråbø 2021-11-08 04:32:49 +01:00
parent 5e87e3edd6
commit 6cbf480307

View file

@ -252,8 +252,8 @@ def construct_request(address, words=1, action=ACTION_READ, marker=0xFF):
return struct.pack("!BBHH", marker, action, address, words) return struct.pack("!BBHH", marker, action, address, words)
def log(message: object): def log(*message: object):
print(datetime.datetime.utcnow().isoformat(" "), message) print(datetime.datetime.utcnow().isoformat(" "), *message)
sys.stdout.flush() sys.stdout.flush()
@ -346,13 +346,19 @@ if __name__ == "__main__":
# CMD_GET_BATTERY_STATE + CMD_GET_PANEL_STATUS # CMD_GET_BATTERY_STATE + CMD_GET_PANEL_STATUS
res = readMemory(dev, 0x0100, 11) res = readMemory(dev, 0x0100, 11)
if res: if res:
try:
d = parse_battery_state(res) d = parse_battery_state(res)
log(d) log(d)
except struct.error:
log("0x0100 Unpack error:", res)
if per_current_hist(now): if per_current_hist(now):
res = readMemory(dev, 0x010B, 21) res = readMemory(dev, 0x010B, 21)
if res: if res:
try:
d = parse_historical_entry(res) d = parse_historical_entry(res)
log(d) log(d)
except struct.error:
log("0x010B Unpack error:", res)
# print(".") # print(".")
time.sleep(1) time.sleep(1)