Hi.
I have some issues I don't understand with inserting float data in to the modbus flex-servers buffer and read that data with a modbus flex-getter when that data is in little endian.
First an example that I'm able to understand/work. Big endian.
Function node preparing the insert to flex-server:
const airTemp = 5.0
const airTempBuffer = Buffer.alloc(4)
airTempBuffer.writeFloatBE(airTemp, 0)
msg.payload = {
'value': airTempBuffer,
'register': 'holding',
'address': 5000,
'disableMsgOutput': 1
}
return msg;
And in the body of the GetHolding in the flex-server you return this:
return node.registers.readUInt16BE(addr * node.bufferFactor)
Then the request preparation:
const request = {
"fc": 3,
"unitid": 1,
"address": 5000,
"quantity": 2
}
msg.payload = request
return msg;
The response payload:
{"data":[16544,0],"buffer":[64,160,0,0]}
With this I can interpret the data:
msg.payload.buffer.readFloatBE().toFixed(1)
This gives me "5.0"
Nice!
But if I do this:
airTempBuffer.writeFloatLE(airTemp, 0)
The response payload is this:
{"data":[0,0],"buffer":[0,0,0,0]}
Why does little-endian give: {"data":[0,0],"buffer":[0,0,0,0]}
Expected behavior in my mind would be something like this: {"data":[0,16544],"buffer":[0,0,64,160]}
Best regards
Steffen