To do arithmetic operations on node red Serial input binary buffer data.

2,936 views
Skip to first unread message

vasanth dhinakaran

unread,
Sep 13, 2017, 2:42:25 AM9/13/17
to Node-RED
msg : Object
object
payloadbuffer[64]raw
[0 … 9]
00x51
10x39
20x0
30x0
40x0
50x2
60x0
70x0
80x0
90x0
[10 … 19]
100x0
110x0
120x1
130xa2
140x0
150x0
160x1
170xa5
180x0
190x0
[20 … 29]
[30 … 39]
[40 … 49]
[50 … 59]
[60 … 63]
_msgid"607a26a3.9f85d8"

For example i want to do buffer[12]*256+buffer[13];
How can i do it? 

Nick O'Leary

unread,
Sep 13, 2017, 2:47:11 AM9/13/17
to Node-RED

That shows the buffer you are interested in is under msg.payload.

So the elements you mention can be referenced as msg.payload[12] and msg.payload[13] for example.

Nick


--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/28ee1481-25e0-4227-96de-bbc2e5ba93cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vasanth Dhinakaran

unread,
Sep 13, 2017, 3:01:05 AM9/13/17
to Node-RED
Inside a function...I tried doing the following and connected a debug 
var MSB = { payload: msg.payload[12] };
var LSB = { payload: msg.payload[13] };
var Vtg = MSB*256+LSB;
return Vtg;

I got the following:
function : (error)
"Function tried to send a message of type string"
var MSB = msg.payload[12] ;
var LSB = msg.payload[13] ;
var Vtg = MSB*256+LSB;
return Vtg;

function : (error)
"Function tried to send a message of type number"
What is the right way to do this? .Thanks for the prompt reply

Nick O'Leary

unread,
Sep 13, 2017, 3:04:59 AM9/13/17
to Node-RED

Functions must return message objects not raw values. Typically you'd update msg.payload with the value you want and return the message:

var MSB = msg.payload[12] ;
var LSB = msg.payload[13] ;
var Vtg = MSB*256+LSB;

msg.payload = Vtg;
return msg


Vasanth Dhinakaran

unread,
Sep 13, 2017, 3:09:48 AM9/13/17
to Node-RED
Thank you Nick.It worked now.
Reply all
Reply to author
Forward
0 new messages