-
I am trying to create simple SerialModbusServer using pymodbus library and then I want to read some not exisiting registers. I expect getting a modbus "Illegal Data Address" error but as I understand it correctly I'm getting "Slave Device Failue": Can anyone explain what am I doing wrong? I was also trying to use ModbusSequentialDataBlock but with similat results. PS I was really trying to show my code in a proper code block using editor but I always ended up like this: (EDIT by def run_server():
nreg = 200
hr_data = {i: 17 for i in range(nreg)}
store = ModbusSlaveContext(
di=ModbusSparseDataBlock({i: 15 for i in range(nreg)}),
co=ModbusSparseDataBlock({i: 16 for i in range(nreg)}),
hr=ModbusSparseDataBlock(hr_data), # tylko adresy 0-199
ir=ModbusSparseDataBlock({i: 18 for i in range(nreg)})
)
context = ModbusServerContext(slaves=store, single=True)
StartSerialServer(
context=context,
port=com_port,
baudrate=9600,
bytesize=8,
parity="N",
stopbits=1,
timeout=1
) Client code: def test_virtual_device():
client = ModbusSerialClient(port="/dev/pts/3", baudrate=9600, bytesize=8, parity="N", stopbits=1)
try:
print("\n--- Reading register 1000 ---")
result = client.read_holding_registers(address=1000, count=5, slave=1)
if result.isError():
print("error", result) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Not sure I understand what you want, a server do not read data. You do not write which version of the library you use, so I assume it is the newest. If you refer to the client, then the reason is probably that you did not define slave 1 in the server. Did you try to to read valid data first ? Normally you would get illegal address if the slave is correct. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
@symygy Jan came up with a better solution in #2733
If you try the very latest
dev
your existing client code should now see IllegalDataAddress.