условно рабочее логгирование насосной, остатки удаления модели насосной станции из БД

This commit is contained in:
2024-01-23 17:40:20 +03:00
parent 9aab833a57
commit 250a4361ee
6 changed files with 85 additions and 43 deletions

View File

@@ -4,6 +4,7 @@ from threading import Thread
import time
from datetime import datetime, timedelta
from pyModbusTCP.client import ModbusClient
from threading import Lock
class MbClearHistoryService(Thread):
@@ -117,27 +118,76 @@ class MbTankService(MbService):
class MbPumpService(MbService):
_config = {
"modbus": {
"host": "10.8.105.2",
"port": 503,
"log-type": "on-change"
},
"registers": [
["D0", "v231_v236"],
["D1", "v236_v29"],
["D15", "ps_39"],
["D16", "flow_meter"],
["D28", "pump_stage"],
["D30", "half_auto_control"],
["D31", "watch_1"],
["D32", "watch_2"],
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._lock = Lock()
["D33", "st_valves"],
["D35", "alarms"],
self._curr_state = None
# {
# "level": int,
# "status": int,
# "radar": int
# }
def _init_state(self):
pass
def _push_current_state(self):
pass
def _load_current_state(self):
# D16: flow_meter
# D28: pump_stage
# D30: half_auto_control
# D31: watch_1
# D32: watch_2
# D33.14: sc_st_pump_31_run
# D33.15: sc_st_pump_31_run
# D35: alarms
# D25: vfd_freq
# D26: vfd_current
# D27: vfd_error
off = 16
values = self.mb.read_holding_registers(16, 35 - off)
with self._lock:
# определение запущенного насоса
pr = None
if values[33 - off] & (1 << 14):
pr = 1
elif values[33 - off] & (1 << 15):
pr = 2
self._curr_state = {
'alarms': values[35 - off],
'flow_meter': values[16 - off],
'last_update': int(datetime.now().timestamp()),
'pump_stage': values[28 - off],
'vfd_curr': values[26 - off],
'vfd_err': values[27 - off],
'vfd_freq': values[25 - off],
'pump_running': pr,
'pump_moto_watch_1': values[31 - off],
'pump_moto_watch_2': values[32 - off],
'half_auto_control': values[30 - off]
}
def _check_need_save(self):
return False
def get_stats(self):
with self._lock:
# копируем данные, если они есть в текущем состоянии (иначе пустые поля)
return self._curr_state or {
'alarms': None,
'flow_meter': None,
'last_update': None,
'pump_stage': None,
'vfd_curr': None,
'vfd_err': None,
'vfd_freq': None,
'pump_running': None,
'pump_moto_watch_1': None,
'pump_moto_watch_2': None,
'half_auto_control': None
}
["D25", "vfd_freq"],
["D26", "vfd_current"],
["D27", "vfd_error"]
]
}