- 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
24 lines
952 B
Python
24 lines
952 B
Python
# -*- coding: utf-8 -*-
|
||
"""在 COM4 上用不同帧格式探测从站 10,定位 Modbus Poll 参数差异。
|
||
对角线实验:N/E/O 校验 × 1/2 停止位。"""
|
||
from pymodbus.client import ModbusSerialClient
|
||
|
||
for parity, stopbits in (("N", 1), ("E", 1), ("O", 1), ("N", 2)):
|
||
client = ModbusSerialClient(
|
||
port="COM4", baudrate=19200, bytesize=8, parity=parity, stopbits=stopbits, timeout=0.8,
|
||
)
|
||
try:
|
||
ok = client.connect()
|
||
if not ok:
|
||
print(f"8-{parity}-1 stop{stopbits}: 打开失败")
|
||
continue
|
||
rr = client.read_holding_registers(0, count=8, slave=10)
|
||
if rr.isError():
|
||
print(f"8-{parity}-{stopbits}: 异常响应")
|
||
else:
|
||
print(f"8-{parity}-{stopbits}: OK 寄存器0~7={rr.registers[:4]}...")
|
||
except Exception as e: # noqa: BLE001
|
||
print(f"8-{parity}-{stopbits}: 无响应 ({type(e).__name__})")
|
||
finally:
|
||
client.close()
|