brainelectronics / micropython-modbus

MicroPython Modbus RTU Slave/Master and TCP Server/Slave library
GNU General Public License v3.0
104 stars 45 forks source link

Bugfix: 'on_get_cb': return value was swallowed #83

Open hmaerki opened 8 months ago

hmaerki commented 8 months ago

Bug

Bugfix

GimmickNG commented 8 months ago

I think I did something like this earlier as well. The problem is that caching it this way means that on_get_cb also has no chance to update the vals the way it's implemented now -- so the tests where it calls set_ireg in the on_get_cb might fail, since it expects the register values to update after it is called - but it would end up returning the old value instead of the new one.

hmaerki commented 7 months ago

I think I did something like this earlier as well. The problem is that caching it this way means that on_get_cb also has no chance to update the vals the way it's implemented now -- so the tests where it calls set_ireg in the on_get_cb might fail, since it expects the register values to update after it is called - but it would end up returning the old value instead of the new one.

Hi @GimmickNG Thanks for your feedback. I could not follow your explanation as I do not know the library sufficiently. I was struggling due to lack of documentation or lack of examples (or I did just missed important parts).

Reading the documentation/examples, I failed to understand how to implement these concepts:

Eventually, the developer has to decide between these two concepts

It might be helpful to have the documentation and examples structured this way.

If you like, I could spend some hours in creating