Payload's number to two 16 bit register to be send via modbus

Hi !
U can use this code in function....after connect it to Modbus Flex Write

function float32ToUint16(value) {  
  var buffer = new ArrayBuffer(4);
  var intView = new Uint16Array(buffer);
  var floatView = new Float32Array(buffer);

  floatView[0] = value;
 

  return [intView[0], intView[1]];
}

//var incoming = JSON.parse(msg.payload);

//Compose ModBus message (Holding Registers) READ/WRITE
var modbusHR = {
 payload : {
 'value' : [
 float32ToUint16(msg.payload)[0], 
 float32ToUint16(msg.payload)[1],
 ],
 'fc' : 16,
 'unitid' : 1,
 'address' : 4,
 'quantity' : 2
 }
};

node.send([modbusHR]);
1 Like