I am trying to read and write data over Modbus TCP with python. When I am using ModbusPoll with the following setup everything works.
I try to read the data now with python and I am using the pymodbus library for this. My code looks like this:
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
But I am always getting the following error:
ModbusIOException(InvalidMessageReceivedException('No response received, expected at least 2 bytes (0 received)'), 1)
Read holding register needs a unit to correctly read the message
read = client.read_holding_registers(address=4000, unit=1)