Modbus 错误:[输入/输出] Modbus 错误:[无效消息] 未收到响应,预计至少 8 个字节(已收到 0 个) pymodbus TCP python 华为

问题描述 投票:0回答:1

我有一个带有加密狗的华为SUN 2000逆变器和一个树莓派4B。我正在尝试使用 pymodbus 库通过 modbus TCP 读取数据,但出现以下错误: Modbus 错误:[输入/输出] Modbus 错误:[无效消息] 未收到响应,预计至少 8 个字节(收到 0 个字节)。使用node-red,在树莓派上,我能够获取数据,但使用python却不能。另外,使用相同的脚本,我可以从 Fronius 逆变器读取数据,所以我不知道问题出在哪里......

我留下代码:

from pymodbus.client import ModbusTcpClient

# Configure the connection to the remote device
client = ModbusTcpClient('192.168.1.100', port=502, timeout=100, retry=3) # Replace the IP address with that of the Huawei device

# Connect to the remote device
client.connect()

# read the value of the holding register 40001
result = client.read_holding_registers(address=30000, count=10, slave=0x00) # Replace the unit number with the value of the Huawei device

# close the connection
client.close()

# Print the value of the holding register
print(result)

我有一个带有加密狗的华为SUN 2000逆变器和一个树莓派4B。我正在尝试使用 pymodbus 库通过 modbus TCP 读取数据,但出现以下错误: Modbus 错误:[输入/输出] Modbus 错误:[无效消息] 未收到响应,预计至少 8 个字节(收到 0 个字节)。使用node-red,在树莓派上,我能够获取数据,但使用python却不能。另外,使用相同的脚本,我可以从 Fronius 逆变器读取数据,所以我不知道问题出在哪里......

raspberry-pi tcpclient huawei-mobile-services pymodbus
1个回答
0
投票

尝试添加 unit=1

client = ModbusTcpClient('192.168.1.100', port=502, timeout=100, retry=3, unit=1) # Replace the IP address with that of the Huawei device

对我有用。

© www.soinside.com 2019 - 2024. All rights reserved.