Skip to content

Commit 3ab67ec

Browse files
committedDec 27, 2022
Error counter for US2000 communication. Access with: /debug/bmsstats
1 parent 10b6cb1 commit 3ab67ec

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
 

‎us2000.py

+10
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ def __init__(self, port=None, baudrate=115200, pack_number=1, lifetime=10, log_n
7575
"analog_timeout": [time.perf_counter() + self.lifetime] * pack_number,
7676
"alarm_timeout": [time.perf_counter() + self.lifetime] * pack_number}
7777

78+
self.stats = {"frame_count": 0,
79+
"error_analog": [0]*self.pack_number,
80+
"error_alarm": [0]*self.pack_number}
81+
7882
self.connect()
7983
self.thread = Thread(target=self.run, daemon=True)
8084
self.thread.start()
@@ -91,6 +95,8 @@ def run(self):
9195
while True:
9296
if self.com is None:
9397
self.connect()
98+
else:
99+
self.stats['frame_count'] += 1 # count read cycle
94100

95101
for i in range(self.pack_number):
96102
try:
@@ -105,6 +111,7 @@ def run(self):
105111
self.log.error("read_analog_value: io port failed")
106112
except Exception as e:
107113
self.data_detail['analog'][i] = None
114+
self.stats['error_analog'][i] += 1 # count error
108115
self.log.debug("EXCEPTION read_analog_value[{}] {}".format(i, e))
109116

110117
self.update()
@@ -122,6 +129,7 @@ def run(self):
122129
self.log.error("read_alarm_info: io port failed")
123130
except Exception as e:
124131
self.data_detail['alarm'][i] = None
132+
self.stats['error_alarm'][i] += 1 # count error
125133
self.log.debug("EXCEPTION read_alarm_info[{}] {}".format(i, e))
126134

127135
self.update()
@@ -130,6 +138,8 @@ def run(self):
130138

131139

132140

141+
142+
133143
def update(self):
134144
t = time.perf_counter()
135145

‎web.py

+2
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ def web_debug_cmd(self, cmd):
187187
if cmd == 'mp2online':
188188
s = "mp2online debug command"
189189
self.app.multiplus.online = True
190+
elif cmd == 'bmsstats':
191+
return self.app.bms.stats
190192
else:
191193
s = "unknown debug command: {}".format(cmd)
192194
self.log.info(s)

0 commit comments

Comments
 (0)
Please sign in to comment.