Open ghost opened 4 years ago
I'm sorry for this late response. I missed this issue. I think I like the idea of configuring a callback. I need to thing about a nice API, but I can already share my first ideas.
I think one should be able to configure a callback for one or several function codes. The callback is than called with an instance of umodbus.functions.ModbusFunction
. I'm not sure yet what the callback should return.
Also what should happen if one has integrated both a callback for a specific function code as well as a 'regular' route? Should both executed? If so, in what order?
I see a need for an ability to get a callback with all the values in a multi-read or multi-write request at once. The callback would then return a list (or iterator) of values in the case of a read operation.
In my case I have a situation where typically 2 adjacent modbus registers map to the high/low parts of an internal parameter, and I want to be able to handle writes atomically and send data from the same point in time for reads.
I don't see an obvious way to add this functionality, though, and right now I inject an alternative implementation of WriteMultipleRegisters.execute() that doesn't have the loop but calls the callback immediately instead.
This is related to #73, and would provide a more generally useful interface (IMHO).