Files
yangpengyu 9eaf87ab7d 现场调试版同步:S331 点表修正(CDAB/scale 60/int32) + SafeRTUFramer 多点485 + 哨兵过滤
- config.yaml: 恢复现场 IP(10.50.253.165/.181/.182)、s331_2 端口 502
- config.yaml: S331 全部 32 位量 word_order 改 CDAB,瞬时流量 scale=60 (m3/min -> m3/h)
- config.yaml: 11# 电表功率/电能类型改 int32;第二路 RTU 从站 slave_id 改 10
- poller.py: 过滤 S331 无数据哨兵 -9999 与非有限值,避免污染周期基准
- rtu.py: 新增 SafeRTUFramer 支持多点半总线,忽略其它从站请求
- 新增 config.debug.yaml、README.md、wheelhouse 离线依赖
- tests: 适配新配置(ttyS7/address_offset);新增 pytest.ini 限定 testpaths
2026-11-19 10:59:27 +08:00

231 lines
9.6 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 边缘计算网关配置(V3.3 - 蘑菇云电表 + 希尔思 S331 气量,精确点表)
# 有人 EG828-CEW / Debian
# 地址为 Modbus 协议地址(0 基),即 S4C/Modbus Poll 中的 40001 对应 address: 0。
#
# V3.3 相对 V3.2 的关键变化(已全部对齐):
# 1) S331 IP 确定: #1=10.50.253.181 #2=10.50.253.182
# 2) S331 TCP Server 从站地址: #1=10 #2=20(网关作为 TCP Client 读它们时用)
# ⚠ 网关 RTU 对外暴露的 slave_id 现场实测为 10/10(S331 两个屏都按 10 轮询),
# 与上面 TCP 侧的 10/20 分属不同总线,互不干扰。
# 3) S331 气量寄存器地址精确给出(见第 5 节),不再是占位
# 4) ⚠ 现场实测:S331 全部 32 位量为“低字在前”(CDAB),不是文档写的 ABCD。
# 用 ABCD 解会得到 -1e-10、6e34 之类的乱数。已全部改为 CDAB。
# 5) 瞬时流量原始单位是 m³/min,配置里用 scale: 60 换算成 m³/h,
# 这样瞬时气电比 = kW / (m³/h) = kWh/m³,与时/日/月口径一致。
# 6) 11# 电表功率/电能 type 实测为 int32(按 float32 解恒为 0)
#
# RTU 从站输出映射(第 6 节)完全不变,和 V3.2 一致。
gateway:
db_path: /var/lib/hx-gateway/gateway.db
log_level: INFO
log_file: ""
persist_interval_s: 300 # 掉电保持周期(秒),5 分钟
status_interval_s: 60 # 状态日志周期
stale_warn_s: 20 # 数据过期告警阈值(秒)
register_float_order: ABCD # RTU 从站 Float 字序(高字在前,即 S4C 里选 FLOAT_B)
devices:
# ---- 蘑菇物联电表 Modbus TCP Server(电表数据源)----
mogo_meter:
host: 10.50.253.165
#host: 192.168.1.253
port: 1502
slave_id: 1
timeout_s: 1.0
poll_interval_s: 2.0
address_offset: 0
max_registers_per_read: 100
max_gap: 6
reconnect_min_s: 1.0
reconnect_max_s: 30.0
# ---- 希尔思 S331 #1 Modbus TCP Server(气量数据源 1)----
# 负责空压机: 3# / 4# / 5# / 11#
s331_1:
host: 10.50.253.181
#host: 192.168.1.253
port: 502
slave_id: 10
timeout_s: 1.0
poll_interval_s: 2.0
address_offset: 0
max_registers_per_read: 100
max_gap: 2
reconnect_min_s: 1.0
reconnect_max_s: 30.0
# ---- 希尔思 S331 #2 Modbus TCP Server(气量数据源 2)----
# 负责空压机: 6# / 7# / 8# / 9# / 10#
s331_2:
host: 10.50.253.182
#host: 192.168.1.253
port: 502
#port: 503
slave_id: 20
timeout_s: 1.0
poll_interval_s: 2.0
address_offset: 0
max_registers_per_read: 100
max_gap: 2
reconnect_min_s: 1.0
reconnect_max_s: 30.0
# ---- 9 台空压机(3#~11#)数据绑定 ----
#
# S331 归属(现场确认):
# s331_1 负责 3# / 4# / 5# / 11# 共 4 台
# s331_2 负责 6# / 7# / 8# / 9# / 10# 共 5 台
#
# ⚠️ V3.3 第 5 节给出的 S331 气量地址,每台机器的 2 个信号(FLOAT_L + UINT32_L)
# 在 S331 上地址相隔 2,紧凑排列。已按设备分组一次 Read Holding Registers 读完。
#
# register_index 决定 RTU 从站基址:base = register_index * 8
# 基址+0/1 瞬时气电比 (ABCD Float)
# 基址+2/3 小时气电比
# 基址+4/5 天气电比
# 基址+6/7 月气电比(后台保留,S331 屏幕暂不展示,寄存器照样实时更新)
compressors:
# ========== s331_1 负责 3# / 4# / 5# / 11# ==========
# 3# 寄存器索引 0 -> 40001~40008
- id: 3
name: "3#空压机"
s331: s331_1
meter: mogo_meter
register_index: 0
flow_instant: { address: 112, type: float32, word_order: CDAB, scale: 60 }
flow_total: { address: 114, type: uint32, word_order: CDAB }
power_instant: { address: 149, type: float32, word_order: ABCD, scale: 0.001 }
energy_total: { address: 151, type: float32, word_order: ABCD, scale: 0.1 }
# 4# 寄存器索引 1 -> 40009~40016
- id: 4
name: "4#空压机"
s331: s331_1
meter: mogo_meter
register_index: 1
flow_instant: { address: 122, type: float32, word_order: CDAB, scale: 60 }
flow_total: { address: 124, type: uint32, word_order: CDAB }
power_instant: { address: 157, type: float32, word_order: ABCD, scale: 0.001 }
energy_total: { address: 159, type: float32, word_order: ABCD, scale: 0.1 }
# 5# 寄存器索引 2 -> 40017~40024
- id: 5
name: "5#空压机"
s331: s331_1
meter: mogo_meter
register_index: 2
flow_instant: { address: 132, type: float32, word_order: CDAB, scale: 60 }
flow_total: { address: 134, type: uint32, word_order: CDAB }
power_instant: { address: 165, type: float32, word_order: ABCD, scale: 0.001 }
energy_total: { address: 167, type: float32, word_order: ABCD, scale: 0.1 }
# 11# 寄存器索引 8 -> 40065~40072
# 现场实测:11# 电表功率/电能为 int32(按 float32 解析恒为 0.0)。
- id: 11
name: "11#空压机"
s331: s331_1
meter: mogo_meter
register_index: 8
flow_instant: { address: 142, type: float32, word_order: CDAB, scale: 60 }
flow_total: { address: 144, type: uint32, word_order: CDAB }
power_instant: { address: 197, type: int32, word_order: ABCD, scale: 0.001 }
energy_total: { address: 199, type: int32, word_order: ABCD, scale: 0.1 }
# ========== s331_2 负责 6# / 7# / 8# / 9# / 10# ==========
# 6# 寄存器索引 3 -> 40025~40032
- id: 6
name: "6#空压机"
s331: s331_2
meter: mogo_meter
register_index: 3
flow_instant: { address: 118, type: float32, word_order: CDAB, scale: 60 }
flow_total: { address: 120, type: uint32, word_order: CDAB }
power_instant: { address: 173, type: float32, word_order: ABCD, scale: 0.001 }
energy_total: { address: 175, type: float32, word_order: ABCD, scale: 0.1 }
# 7# 寄存器索引 4 -> 40033~40040
- id: 7
name: "7#空压机"
s331: s331_2
meter: mogo_meter
register_index: 4
flow_instant: { address: 128, type: float32, word_order: CDAB, scale: 60 }
flow_total: { address: 130, type: uint32, word_order: CDAB }
power_instant: { address: 181, type: float32, word_order: ABCD, scale: 0.001 }
energy_total: { address: 183, type: float32, word_order: ABCD, scale: 0.1 }
# 8# 寄存器索引 5 -> 40041~40048
- id: 8
name: "8#空压机"
s331: s331_2
meter: mogo_meter
register_index: 5
flow_instant: { address: 138, type: float32, word_order: CDAB, scale: 60 }
flow_total: { address: 140, type: uint32, word_order: CDAB }
power_instant: { address: 189, type: float32, word_order: ABCD, scale: 0.001 }
energy_total: { address: 191, type: float32, word_order: ABCD, scale: 0.1 }
# 9# 寄存器索引 6 -> 40049~40056
- id: 9
name: "9#空压机"
s331: s331_2
meter: mogo_meter
register_index: 6
flow_instant: { address: 148, type: float32, word_order: CDAB, scale: 60 }
flow_total: { address: 150, type: uint32, word_order: CDAB }
power_instant: { address: 213, type: float32, word_order: ABCD, scale: 0.001 }
energy_total: { address: 215, type: float32, word_order: ABCD, scale: 0.1 }
# 10# 寄存器索引 7 -> 40057~40064
- id: 10
name: "10#空压机"
s331: s331_2
meter: mogo_meter
register_index: 7
flow_instant: { address: 158, type: float32, word_order: CDAB, scale: 60 }
flow_total: { address: 160, type: uint32, word_order: CDAB }
power_instant: { address: 205, type: float32, word_order: ABCD, scale: 0.001 }
energy_total: { address: 207, type: float32, word_order: ABCD, scale: 0.1 }
# ---- 两个物理串口各跑一个独立 RTU 从站,分别对接 S331 #1 / #2 ----
# 严禁把两个 S331 并接到同一个 485 口
#
# ⚠ 现场部署必查两项(本台 EG828-CEW 实测踩坑记录):
# 1) 串口设备映射与面板丝印不一定一致。核实方法:cat /proc/tty/driver/serial
# 记下各口 rx 计数 → 从 PC 发一帧请求 → 再看哪个口 rx 增长,即为实际映射。
# 2) 有人系统自带 /usr/local/sbin/mcu_ctl(由 /etc/init.d/m300_script/S15mcu_ctl 开机拉起)
# 会占用 ttyS1/ttyS3/ttyS7 并抢走串口收到的数据,导致 RTU 从站收不到请求
# (现象:rx 计数持续增长、tx 不动、S331 全部超时)。
# 停用方法:pkill -9 -f mcu_ctl;再 mv S15mcu_ctl S15mcu_ctl.disabled 并 chmod -x。
# 检查是否残留:fuser -v /dev/ttyS1(应只剩 python)。每次网关重启后都要确认。
#
# 注意:两个口对外都用 slave_id=10(现场 S331 屏实测按 10 轮询)。
# 两条 485 物理独立,同号不冲突;TCP 侧的 10/20 是 S331 自己的地址,也不冲突。
#
# ⚠ 从站固件注意:pymodbus 自带 RTU framer 不支持多点 485,遇到同总线其它设备
# (S331 自己的流量计 67~75)的请求/应答会拼错帧抛异常,导致从站完全不回。
# 代码里已用 SafeRTUFramer 兜住,并对未知从站保持静默(ignore_missing_slaves)。
slaves:
- name: gateway_to_s331_1
port: /dev/ttyS1
slave_id: 10
baudrate: 19200
bytesize: 8
parity: N
stopbits: 1
timeout_s: 0.5
- name: gateway_to_s331_2
# 本台 EG828-CEW 实测串口映射:RS485-1→/dev/ttyS1,RS485-2→/dev/ttyS7(串口计数器实测确认)。
# 现场换网关时如映射不同,用 cat /proc/tty/driver/serial 对比收发计数核实后修改此处。
# ⚠ 现场实测:S331 #2 的屏也是按从站地址 10 轮询本口(不是 20),两条 485 物理独立,同号不冲突。
port: /dev/ttyS7
slave_id: 10
baudrate: 19200
bytesize: 8
parity: N
stopbits: 1
timeout_s: 0.5