【问题标题】:Python Modbus RTU over TCP基于 TCP 的 Python Modbus RTU
【发布时间】:2022-08-16 09:00:01
【问题描述】:

我正在尝试使用 python 通过 Modbus TCP 读取和写入数据。 当我将ModbusPoll 与以下设置一起使用时,一切正常。

我现在尝试使用 python 读取数据,为此我正在使用pymodbus 库。 我的代码如下所示:

from pymodbus.client.sync import ModbusTcpClient
from pymodbus.transaction import ModbusRtuFramer as ModbusFramer

client = ModbusTcpClient(\"192.168.0.7\", port=502, framer=ModbusFramer)
success = client.connect()

read = client.read_holding_registers(address=4000)
read.registers

但我总是收到以下错误:

ModbusIOException(InvalidMessageReceivedException(\'未收到响应,预计至少 2 个字节 (0 收到)\'), 1)

    标签: python modbus modbus-tcp pymodbus modbus-rtu-over-tcp


    【解决方案1】:

    读取保持寄存器需要一个单元才能正确读取消息

    read = client.read_holding_registers(address=4000, unit=1)
    

    【讨论】:

      猜你喜欢
      • 2019-06-17
      • 2019-11-27
      • 2021-04-20
      • 1970-01-01
      • 2016-12-30
      • 2014-03-06
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多