Optional address indexing in ModbusDeviceContext #2792
embedded-bed
started this conversation in
Ideas
Replies: 1 comment
-
You are mixing the definition of data and the requests. Data are defined from 1 and upwards, which corresponds to requests from 0 and upwards. If a request comes with address 0, the += 1 means it is addressed internally as 1, I have no idea how you would request address -1, and also not why. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The
getValues
andsetValues
methods in theModbusDeviceContext
class increments the address by 1:However, this can be troublesome to deal with in the case where the user wants a server with starting register address of 0. Should the client then request the address -1 from the server, since it's incremented internally?
Zero indexing is not uncommon in applications, and providing the option to control the addressing in Pymodbus would be a nice feature.
One proposal could be an optional argument when creating a
ModbusDeviceContext
object:And then in the methods:
Let me know if this is a desired feature or not. I am not sure how you want to handle invalid address offset, right now I just raise a ValueError as an example.
I can create the PR as well, if you would like.
Beta Was this translation helpful? Give feedback.
All reactions