How to div Values from in multiple output function arrary

I have Written a code in function ( Multiple output ) as below which receives the data through modbus

var msg0 = {payload:(msg.payload[0]<<16) + msg.payload[1]};
var msg1 = {payload:(msg.payload[2]<<16) + msg.payload[3]};
return [msg0,msg1];

i'm getting msg0 output of function as as 4145 but i required 41.45. Kindly suggest what code to be written to get the expected output as 41.45.

Divide it by 100

var msg0 = {payload: ((msg.payload[0]<<16) + msg.payload[1]) / 100};
var msg1 = {payload: ((msg.payload[2]<<16) + msg.payload[3]) / 100};
return [msg0,msg1];

At a guess, you are working with modbus data? If so, there is a contrib node designed to help with all the 16 bit / 32 bit / float / masking / bit shifting etc - makes this a trivial and low code experience - node-red-contrib-buffer-parser

1 Like

Dear Steve,

Thanks for the reply.

Yes. We are working MODBUS DATA through ABB AC500 Controller

In Still getting the same out.

can you share the values coming out of the modbus node AND the values you expect them to become?

(add a debug node set to show complete message & use the copy value button to grab a copy of the entire message)

Hi ,

The Values are coming as below.

Values 1: 32768 ,
Values 2:17357
Value coming : 412.
Expected Value : 4.12

Hi could you try again please. Set the debug to show complete message & use the copy value button...

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.