Closed jcameron-sso closed 1 month ago
Your setup is not correct, ModbusSlaveContext does not follow the Api, please see examples/server_async.py
Closing since this is not a bug, but a configuration error. Help is in discussions.
Thanks. Using examples/server_async.py
, removing complexity and features we don't need, our code above is changed to;
block = lambda : ModbusSequentialDataBlock(0, data_registers)
context = ModbusSlaveContext(di=block(), co=block(), hr=block(), ir=block())
So it isn't that Pymodbus.ModbusSlaveContext doesn't follow the Api, but that our use of it did not. My apologies.
Having made that change, the registers are no longer zero, but the registers are offset by one. We provide six registers, but a client can only read five. Client receives the second register value instead of the first register value.
client (REPL)
>>> from pymodbus.client import ModbusTcpClient
>>> client = ModbusTcpClient(...)
>>> client.connect()
True
>>> r = client.read_holding_registers(0, 6)
>>> r.isError()
True
>>> r = client.read_holding_registers(0, 5)
>>> r.isError()
False
>>> r.registers
[8, 380, 168, 133, 192] # unexpected offset by one
server output
[173, 8, 380, 168, 133, 192]
Exception response Exception Response(131, 3, IllegalAddress)
That's because there is a difference on 1 between the memory layout and the addressing...which is due to an old standard that address 0 was not allowed.
There is a "zero_mode" parameter to change that.
Thanks, that fixed it. For your interest, zero_mode
is not discoverable in https://pymodbus.readthedocs.io/en/latest/search.html?q=zero_mode&check_keywords=yes&area=default
Pull requests are welcome.
Good idea, thanks. https://github.com/pymodbus-dev/pymodbus/pull/2187
Versions
Pymodbus Specific
Description
Trying to read registers from a server, data was returned, but data is zero, expected data to be as supplied. tcpdump showed server as cause.
Code and Logs