我正在尝试使用 pymodbus 从 SMA 集群控制器获取数据,但没有得到任何响应。例如,文档说地址 30005 中的请求带有 2 个寄存器和单元 1 我将获得集群控制器的序列号,我得到以下信息:
“ModbusIOException”对象没有属性“寄存器”
我正在使用的代码:
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder as Decoder
import time
client = ModbusClient('192.168.8.103', port=502)
try:
c=client.connect()
print(c)
while c:
result = client.read_holding_registers(30005, 2, unit=1)
print(result.registers)
decoder = BinaryPayloadDecoder.fromRegisters(result.registers, wordorder=Endian.Big, byteorder=Endain.Big)
value = decoder.decode_64bit_uint()
time.sleep(5)
except Exception as e:
print(e)