- 点位字典 CSV schema/加载/自动校验(缺失字段/量纲/重复点号,PRD 5.1) - 协议可插拔只读驱动:OPC UA(S7-1200 适配)/S7/Modbus/称重/能源/模拟 - 周期采集引擎:只读+背压保护+健康度指标(丢失率/P99/可用性) - Kafka 流式上行 + 本地 spool 断点续传(丢失率≤0.02% 保障) - 模板配置外置(gateway.yaml + 点位字典 CSV),换行业零改码 - 18 个单元测试全绿;端到端运行 SLA 达标
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""能源表驱动 —— 电表/水表/气表等能源计量设备参数化适配。
|
||
|
||
能源表多支持 Modbus(DL/T 645 网关转 Modbus)或 DL/T 645 串口规约;
|
||
模板化封装与称重驱动一致:默认走 Modbus 参数化实现,
|
||
`mode: dlt645` 时需现场规约文档定制子类。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
from typing import Dict, List, Optional
|
||
|
||
from point_dict.loader import Point
|
||
from .base import Driver, SampleValue
|
||
from .modbus_driver import ModbusDriver
|
||
|
||
|
||
class EnergyDriver(Driver):
|
||
"""能源表只读采集驱动(参数化适配)。"""
|
||
|
||
protocol = "energy"
|
||
|
||
def __init__(self, config: Optional[dict] = None):
|
||
super().__init__(config)
|
||
self.mode: str = self.config.get("mode", "modbus")
|
||
self._delegate: Optional[Driver] = None
|
||
|
||
def connect(self) -> None:
|
||
if self.mode == "modbus":
|
||
self._delegate = ModbusDriver(self.config)
|
||
else:
|
||
raise ConnectionError(
|
||
"能源驱动非 modbus 模式(如 DL/T 645)需要现场规约文档支持,请实现子类"
|
||
)
|
||
self._delegate.connect()
|
||
|
||
def read_points(self, points: List[Point]) -> Dict[str, SampleValue]:
|
||
if self._delegate is None:
|
||
raise ConnectionError("能源驱动未连接,请先 connect()")
|
||
return self._delegate.read_points(points)
|
||
|
||
def close(self) -> None:
|
||
if self._delegate is not None:
|
||
self._delegate.close()
|
||
self._delegate = None
|