You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: correct float encoding into a slave mapping
packToModbus() wrote floats with modbus_set_float_abcd(), which stores
the four raw wire bytes into the register array. modbus_reply() reads
that array back as host-order uint16 values and serialises each one high
byte first, so on a little-endian host every float left the server with
its bytes swapped inside each word.
Writing 6.25 produced tab_registers[40071] = 0xC840 where the wire needs
0x40C8. Every float register served was wrong, which is why a client
decoding them saw values like 4.2e11 for a power factor.
Route the bit pattern through packInteger<uint32_t>() instead. It already
produces most-significant word first in host order, which is the
convention the reply path and every other multi-register type in this
function use, so the float case now matches its neighbours.
Only the write side was affected. getModbusDouble() decodes floats from a
buffer filled by modbus_read_registers(), a different convention, and
reads real hardware correctly.
Found by serving a float meter model and reading it back through this
library's own Meter: the integer model round-tripped, the float model
returned garbage.