Closed jadamcrain closed 6 years ago
This gave me an excuse to read some code. Very easy to follow.
Would be good during refactoring to see if we can remove the code duplication for holding/input registers:
They're basically the same thing, right?
It was an interpretation of section 4.4 of the Modbus Application Protocol v1.1b3, where it says this:
The MODBUS application protocol defines precisely PDU addressing rules. In a MODBUS PDU each data is addressed from 0 to 65535. It also defines clearly a MODBUS data model composed of 4 blocks that comprises several elements numbered from 1 to n. In the MODBUS data Model each element within a data block is numbered from 1 to n. Afterwards the MODBUS data model has to be bound to the device application ( IEC-61131 object, or other application model). The pre-mapping between the MODBUS data model and the device application is totally vendor device specific.
To be honest, it doesn't make much sense to do that +1 offset just to start at 1 instead of 0. I'll remove that.
I'll also refactor the thing to avoid code duplication as ou suggested.
If you configure a read holding register request, the received addresses are incremented one more than they should be, e.g. the request below results in the log below.
What's being sent over the wire is correct, but the construction of the response has the all the indices incremented by one: