I have a function node that extracts some numbers from binary data. It has been running for years wonderfully but of course I decided to upgrade nodejs and nodered and new Buffer is no longer working and I can seem to understand how to change it to the new safe-buffer.
Can anyone tell me what I’m doing wrong converting new Buffer() to the new safe buffer..
Original code that worked until I upgraded…
var amps = [msg.payload.data[0],msg.payload.data[1]];
var ampsBuff = new Buffer(amps);
amps = ampsBuff.readInt16LE(0)
global.set('globalAmps', amps);
I have tried changing
var ampsBuff = new Buffer(amps) to var ampsBuff = Buffer.from(amps);
I have also tried changing
var ampsBuff = new Buffer(amps) to var ampsBuff = Buffer.alloc(amps);
Sorry buffers are not my strength. I’m just not sure how to create this safe-buffer so that I can extract the number from it.
Thanks for any help