当我尝试以下代码时,我可以连接到智能电表,但我无法读取寄存器内容。
import traceback
from pymodbus.client.sync import ModbusTcpClient
client = ModbusTcpClient('192.168.2.1', port=502)
client.connect()
try:
res = client.read_holding_registers(0x0063, 1, unit=1)
print(res.registers)
except:
traceback.print_exc()
client.close()
给出一个例外
Traceback <Most recent call last>
File "m2.py", Line 8 ,in <module>
print<res.registers>
AttributeErro: 'ModbusIOException' objecthas noattribute 'registers'
请帮我解决这个问题