Skip to content

Simulator not returning proper exception codes. #2642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Lucas-Morais-Freire opened this issue Apr 17, 2025 · 1 comment · Fixed by #2643
Closed

Simulator not returning proper exception codes. #2642

Lucas-Morais-Freire opened this issue Apr 17, 2025 · 1 comment · Fixed by #2643

Comments

@Lucas-Morais-Freire
Copy link

Lucas-Morais-Freire commented Apr 17, 2025

Hi. I would like to report that I have found an use case where the library does not conform to modbus protocol.

Trying to reach invalid addresses should return an exception code 0x02 as per the protocol. The pymodbus library conveniently has a way to label some addresses as invalid in the setup.json file, but this functionality has been a bit broken since the change from 3.9.0.

Steps to reproduce:

  1. clone this simple repo that I made to illustrate the issue.
  2. install version 3.8.6 of pymodbus
  3. execute python simulator.py
  4. execute python client.py 0
  5. execute python client.py 4
  6. Now install version 3.9.0 of pymodbus
  7. repeat steps 3 through 5

The setup.json in this file has only 4 memory locations where addresses 0 and 1 are invalid and addresses higher than 3 do not exist. Observe that with version 3.8.6, accessing address 0 makes the server print the correct function code (131) with the correct exception code (2), because 0 is marked as invalid in setup.json. Still, accessing address 4 should have made the server print the same values as the case with address 0 since it is invalid because its out of range. Instead, the server builds a 0x00 exception response with SLAVE_FAILURE exception code. which the client understands as IO failiure instead of a normal exception. Now, with version 3.9.0, the case with address 0 returns no issue, and the problem with address 4 still exists.

I would really appreciate if you would let me know if I did anything wrong in my setup to cause these issues.

@janiversen
Copy link
Collaborator

First of all, pymodbus library is adhering to the modbus standard, you talk about the server with the simulator datastore and I do not think you have done anything wrong....except maybe not having tried with address 5, since 4 is borderline.

Returning SLAVE_FAILURE is a general failure and not against the modbus standard, actually a lot of "simpler" devices only return this code, however it is correct that the simulator used to return ILLEGAL_ADDRESS.

What the server print is not really not a concern, but what it returns to the client is a concern.

With v3.9.0 some validation was dropped, but it seems that the datastore simulator was cut a bit too deep. Internally we no longer work on that simulator datastore, but with a new simulator (not yet publicly available) which will be part of v4.x.

We will look into making ILLEGAL_ADDRESS appear again, however I am not sure if an out of bound address should be ILLEGAL _ADDRESS, I have 2 devices on my desk which both report SLAVE_FAILURE in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants