谁能解释如何通过 Modbus TCP/IP 使用 pymodbus 以正确的方式创建请求并获得响应?
我有PLC,我想用作从站和PC - 作为主站。
我试图这样做:
from pymodbus.client.sync import ModbusTcpClient
host = '192.168.56.9'
port = 502
client = ModbusTcpClient(host, port)
client.connect()
#Register address 0x102A (4138dec) with a word count of 1
#Value - MODBUS/TCP Connections
#Access - Read
#Description - Number of TCP connections
request = client.read_holding_registers(4138, 1)
response = client.execute(request)
print response
>>> ReadRegisterResponse (1)