1

我已经成功安装了“node-red-contrib-modbus”,并且使用此函数在 modbus 寄存器上进行浮点转换(4 字节寄存器类型)没有问题:

//var data =  [64, 226, 157, 10];
var data =  msg.payload.buffer;

// Create a buffer
var buf = new ArrayBuffer(4);
// Create a data view of it
var view = new DataView(buf);

// set bytes
data.forEach(function (b, i) {
    view.setUint8(i, b);
});

// Read the bits as a float; note that by doing this, we're implicitly
// converting it from a 32-bit float into JavaScript's native 64-bit double
var num = view.getFloat32(0);
// Done
//console.log(num);

msg.payload = num;

return msg;

如何转换“signed long long”(8字节)????

我已经尝试在谷歌上搜索,但问题仍然存在......

4

0 回答 0