使用节点红色从 modbus TCP 读取 32 位浮点数 [英] Reading 32 bit Float from modbus TCP using node red

查看:582
本文介绍了使用节点红色从 modbus TCP 读取 32 位浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何读取带有节点红色功能块的 modbus TCP 保持值 (03) - 32 位浮点字交换 (CD AB)?

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

我对 modbus 有问题...

I have problem with modbus...

从 modbus TCP 读取(FC3,数据大小 32 位浮点数,地址 272 十进制)...

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

当节点 RED 读取值(FC 3,读取保持寄存器,数量 2)返回类似 [0,16833] 的值时......这里我在函数中使用 msg.payload=msg.payload[1] 来获取值16833 出数组...

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..

要查看 modbus 地址是否正确,我正在使用外部应用程序从传感器读取值(Rilheva modbus poll)...

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

设置为 :

读取保持值 (03) - 32 位浮点字交换 (CD AB) - 见屏幕...

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

那么,有人知道如何将其转换为实际值吗?这里是 24.25...

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

推荐答案

您可以先将两个整数保存到缓冲区中(交换您在 OP 中提到的单词).之后,将缓冲区读取为浮点数.

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;

使用您的样本数据 [0,16833] 进行测试时,您将得到 msg.payload = 24.125

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

这篇关于使用节点红色从 modbus TCP 读取 32 位浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆