Warm tip: This article is reproduced from serverfault.com, please click

Reading 32 bit Float from modbus TCP using node red

发布于 2019-05-22 13:12:32

how to read modbus TCP holding values (03) - 32bit float word swap (CD AB) with node red function block ?

I have problem with modbus...

Reading from modbus TCP ( FC3 , data size 32 bit Float, address 272 decimal)...

When Node RED read values ( FC 3, read holding registers, quantity 2 ) returns values like [0,16833] ... Here I'm using msg.payload=msg.payload[1] in function to get value 16833 out from array...

This is my temperature sensor value..

To see if modbus address is correct I'm using external app to read values from sensors ( Rilheva modbus poll ) ...

Correct value is reading from PLC module when is set to :

Read holding values (03) - 32bit float word swap (CD AB) - see screen...

So, does anybody knows how to convert it to real value - here it is 24.25...

Questioner
Damir Švegović
Viewed
0
AIOT MAKER 2019-05-23 07:18:28

You can first save the two integers to a buffer (swapping the words as you mentioned in the OP). Afterward, read the buffer as a float.

This is how the function node will look like (first line added for testing purposes).

msg.payload = [0, 16833];
let pay = msg.payload;

const buf = Buffer.allocUnsafe(4);
buf.writeInt16BE(pay[0],2);
buf.writeInt16BE(pay[1],0);

msg.payload = buf.readFloatBE(0);
return msg;

When testing with your sample data [0,16833] you will get msg.payload = 24.125