поправил чтение накопленного расхода с HART модема
This commit is contained in:
parent
0195373cc4
commit
b8d0ce72c4
@ -4,6 +4,7 @@ from threading import Thread
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
from pyModbusTCP.client import ModbusClient
|
||||
from pyModbusTCP.utils import decode_ieee
|
||||
from threading import Lock
|
||||
|
||||
|
||||
@ -190,18 +191,25 @@ class MbHartService(MbService):
|
||||
|
||||
def _load_current_state(self):
|
||||
# D?: flow_meter
|
||||
values = self.mb.read_holding_registers(600, 1)
|
||||
values = self.mb.read_input_registers(1304, 2)
|
||||
if values is None:
|
||||
raise AssertionError('failed to load current state')
|
||||
|
||||
def swap_bytes(source):
|
||||
return (source & 0xFF) << 8 | (source & 0xFF00) >> 8
|
||||
|
||||
decoded = decode_ieee((swap_bytes(values[0]) << 16) | swap_bytes(values[1])) # тут еще ебаный byte-swap
|
||||
with self._lock:
|
||||
self._curr_state = {
|
||||
'accumulated_flow': values[0]
|
||||
'accumulated_flow': int(decoded),
|
||||
'last_update': int(datetime.now().timestamp()),
|
||||
}
|
||||
|
||||
def get_stats(self):
|
||||
with self._lock:
|
||||
# копируем данные, если они есть в текущем состоянии (иначе пустые поля)
|
||||
return self._curr_state or {
|
||||
'accumulated_flow': None
|
||||
'accumulated_flow': None,
|
||||
'last_update': None,
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user