Добавил еще одно устройство в проект: HART модем, получающий накопленный расход от расходометра.

This commit is contained in:
2024-02-21 15:44:55 +03:00
parent 4da1ce477e
commit 0195373cc4
7 changed files with 87 additions and 11 deletions

View File

@@ -181,3 +181,27 @@ class MbPumpService(MbService):
'half_auto_control': None
}
class MbHartService(MbService):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._lock = Lock()
self._curr_state = None
def _load_current_state(self):
# D?: flow_meter
values = self.mb.read_holding_registers(600, 1)
if values is None:
raise AssertionError('failed to load current state')
with self._lock:
self._curr_state = {
'accumulated_flow': values[0]
}
def get_stats(self):
with self._lock:
# копируем данные, если они есть в текущем состоянии (иначе пустые поля)
return self._curr_state or {
'accumulated_flow': None
}