Register Map convenience class for operating on device registers #2222
jameshilliard
started this conversation in
Ideas
Replies: 1 comment 9 replies
-
I think I understand what you suggest, for the server we have done that in form of the simulator, for the client we have been thinking about a higher level API that do e.g. ReadInt32, but never came around to implement it. I cannot tell you why the payload functions work as they do, they are very old, and to a large on the way out...today we offer convert_from_registers, convert_to_registers with a datatype parameter as a much more efficient way of decoding/encoding. I think you idea is very interesting, it is however still a bit vague to me how to convert it into actual code. |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So I'm not sure if this is something that has been done with pymodbus before but I think it might be nice to have some sort of device register memory mapped convenience class/classes that gets initialized with all known device registers(ie based on device documentation) that would let you operate on registers as fields of some sort and potentially provide proxy methods that do device register read/writes based on mapped fields without having to re-specify field details like address and data types which would be provided in the initializer.
I'm thinking this would provide a cleaner register decoding capability along the likes of
BinaryPayloadDecoder
but would be initialized with a map of all device registers and allow mirroring of groups of registers along with out of order register payload decoding via field accessor methods of some sort.Building register mapping classes was something I did in the past with a protocol that shares some similarities to modbus called upb that uses 8 bit register reads/writes instead of the 16 bit register reads/writes that modbus uses. To construct these memory map classes I essentially used a ctypes.BigEndianStructure to essentially provide register maps mirrored from the devices.
The main reason I think something like this would be helpful for modbus is that the existing decoder classes like
BinaryPayloadDecoder
have some limitations that seem to inherently result in unnecessary code duplication when it comes to register address definitions/mappings, for exampleBinaryPayloadDecoder
doesn't allow for specifying ahead of time a full device register map that can be easily reused across different read/write operations.BinaryPayloadDecoder
also requires retrieving register values by doing call order dependent reads on register data fields and thus isn't really suitable for storing register data for accessing later. In cases where we may want to provide two methods for say updating a large group of registers along with a smaller group of registers that is a subset of the larger group there doesn't seem to be a convenient way to decode the registers without essentially duplicating the code calling theBinaryPayloadDecoder
decoder methods which is somewhat error prone as we then have to manually build partial register maps in our code calling theBinaryPayloadDecoder
decoder/read methods.Is there a reason
BinaryPayloadDecoder
uses pointer based decode operations for register decoding rather than say have those methods decode based on_payload
address offsets passed to the decode methods or something along those lines?Beta Was this translation helpful? Give feedback.
All reactions