CAN communication via candump

700 views
Skip to first unread message

Andre1000

unread,
Feb 13, 2017, 4:35:29 PM2/13/17
to Node-RED
Hello,

I have a problem with the communication via CAN-Bus. The function candump is working. With the function cansend I can't send my values.
I will send a Intager-value in a range from 0 to 255 as hex-value on ID 081.
At this time I don't find a script for this conversion.

Has anywhere a idea or a example?

Thank you,

André

Colin Law

unread,
Feb 13, 2017, 4:42:04 PM2/13/17
to node...@googlegroups.com
Which node are you using?

Colin
> --
> 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/12ff7cac-0382-46cb-8e04-c96b7726616e%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Andre1000

unread,
Feb 14, 2017, 12:48:43 AM2/14/17
to Node-RED
I use

node-red-contrib-canbus 1.0.1

Colin Law

unread,
Feb 14, 2017, 5:55:34 AM2/14/17
to node...@googlegroups.com
OK, can I just check that I understand what the question is. You have
a value in the range 0 to 255 and you wish to convert it to a hex
string and concatenate it with an id number, so that for id 081 and
value, for example 255 you wish to generate the string "081#ff" which
you can then pass to the can node.

If so then I think you want a function containing something like:

var id = "081";
var hexString = msg.payload.toString(16);
msg.payload = id + "#" + hexString;
return msg;

Colin
> --
> 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/9b2bd256-3c1e-4c92-9494-c36f5f0b74ab%40googlegroups.com.

Andre1000

unread,
Feb 14, 2017, 1:19:15 PM2/14/17
to Node-RED
Dear Colin,

thank you foryou answer. This is nearly identical to my way.
When I use your code, I have the same result.
I send the integer 15 your code will transfer this to the masage "payload": "081#f" this will send directly to the cansend node. On the canbus I read the massage 051 [1] 66.
The hex string will transferd with their ASCII value.
I had one other idea. I transferd the integer with String.fromCharCode(msg.payload). The problem is, that this function works only in the range 0..127 (0x00..0x7f).
In my meaning, the cansend node interpret the data as char an transfer this to the ASCII code.

Do you have an idea?

André

Colin Law

unread,
Feb 14, 2017, 3:55:32 PM2/14/17
to node...@googlegroups.com
Sorry, you have lost me. Can you give me an example of the data you
are starting with and what string you want to generate to feed to the
node?

Colin
> https://groups.google.com/d/msgid/node-red/63eefca4-0778-400a-ac22-dd9903b3cf23%40googlegroups.com.

Andre1000

unread,
Feb 14, 2017, 4:56:24 PM2/14/17
to Node-RED

Sorry, for my bad explanations.

I have adapt your example to
var id = "081";
var Integer=10;
var hexString = Integer.toString(16);

msg.payload = id + "#" + hexString;
return msg;

the message on the CAN-Bus is:
051   [1]  61

when I change
var Integer=5, than  051   [1]  35

my target is to see the  message on the CAN-Bus
Integer=5 ->  051   [1]  05
Integer=10 ->  051   [1]  0A
Integer=255 ->  051   [1]  FF

hopefully, now it is clear.

André

Colin Law

unread,
Feb 14, 2017, 5:04:09 PM2/14/17
to node...@googlegroups.com
Remember I have no knowledge of Canbus. What I would like is an
example that shows what string you want to send to the node, given
some values. Then hopefully I can suggest how to convert the values to
the string.

Colin
> https://groups.google.com/d/msgid/node-red/232539e0-830a-4db7-88a9-805817bb6cb2%40googlegroups.com.

Andre1000

unread,
Feb 15, 2017, 2:51:14 PM2/15/17
to Node-RED

Dear Colin,

here my flow with some values



André

steve rickus

unread,
Feb 15, 2017, 4:09:45 PM2/15/17
to Node-RED
I think this requires the last character (the 05, 0A, and FF in your example) to be a single 16-bit char.
Instead of converting the msg.payload to a hex string, try this:

var id = "081";
var intValue = +msg.payload;
var chrValue = String.fromCharCode(intValue);

msg
.payload = id + "#" + chrValue;
return msg;

The real solution here is (probably) to use an ArrayBuffer to build a more structured array of bytes that the canbus will properly interpret on the other end of the serial connection. That's a bit more involved, so try this first and we can do the other if this does not work.
--
Steve

Rajesh Sola

unread,
Feb 21, 2017, 9:59:52 AM2/21/17
to Node-RED
Dear Andre,
               I am happy to see the usability of canbus nodes,which i wrote two year back....as you mentioned candump node is working outright and cansend node has few issues....to summarize inputs to cansend node can be provided in one of the following ways
1.explicitly msg.canid and msg.payload
2.msg.payload in the form for id#data   (as you are using currently)
3.only data in msg.payload, id will be taken from node configuration or randomly
4.Default canid or data in cansend node configuration
5.Random values if any of the filed is absent (not filled in node configuration or thru input wire)

However first method may be most suitable and flexible i feel..please share your feedback to enhance the node behaviour
dlc is calcuated based given data always..planning to add support payload in the form of object having id, data as fields(msg.payload.id, msg.payload.data),slight change w.r.t input method-1...I am fine tuning the priority of input methods slightly...hopefully will update the node over this weekend.

Please find an example flow covering most of the test cases of cansend node usability,which is tested on Virtual CAN.The last input in this example is forming hex data as buffer,instead of string,hope it is near to your expectation.

Thanks,
Rajesh Sola.
ps:- facing some problem in attaching flow..so pasting here

[{"id":"f8373930.780ef8","type":"cansend","z":"8ed637d.a0a6448","config":"245413cb.1c6014","canid":"128","payload":"ABCD","x":535.7832641601562,"y":151.08338928222656,"wires":[]},{"id":"c213fd9b.c5ed68","type":"inject","z":"8ed637d.a0a6448","name":"","topic":"","payload":"abcd","payloadType":"str","repeat":"","crontab":"","once":false,"x":141.7833251953125,"y":151.00001525878906,"wires":[["70b2bdd2.df8f7c"]]},{"id":"70b2bdd2.df8f7c","type":"change","z":"8ed637d.a0a6448","name":"","rules":[{"t":"set","p":"canid","pt":"msg","to":"100","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":330.7833251953125,"y":150.83334350585938,"wires":[["f8373930.780ef8","593b8ff0.242cb8"]]},{"id":"9d4958ed.aeca2","type":"inject","z":"8ed637d.a0a6448","name":"","topic":"","payload":"192#xyzabc","payloadType":"str","repeat":"","crontab":"","once":false,"x":160.7833251953125,"y":216.00003051757812,"wires":[["f8373930.780ef8","593b8ff0.242cb8"]]},{"id":"3ffcc1fe.137d46","type":"inject","z":"8ed637d.a0a6448","name":"","topic":"","payload":"hello","payloadType":"str","repeat":"","crontab":"","once":false,"x":142.78334045410156,"y":271,"wires":[["f8373930.780ef8","593b8ff0.242cb8"]]},{"id":"593b8ff0.242cb8","type":"cansend","z":"8ed637d.a0a6448","config":"245413cb.1c6014","canid":"","payload":"","x":587.0833129882812,"y":252.0833740234375,"wires":[]},{"id":"170b039d.f543fc","type":"inject","z":"8ed637d.a0a6448","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":143.78330993652344,"y":323,"wires":[["593b8ff0.242cb8","f8373930.780ef8"]]},{"id":"b4dc163f.58e788","type":"inject","z":"8ed637d.a0a6448","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":149.0833282470703,"y":377.0833435058594,"wires":[["5361baf3.55204c"]]},{"id":"5361baf3.55204c","type":"change","z":"8ed637d.a0a6448","name":"","rules":[{"t":"set","p":"canid","pt":"msg","to":"320","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":334.0832824707031,"y":378.08335876464844,"wires":[["f8373930.780ef8","593b8ff0.242cb8"]]},{"id":"a6ee6089.672528","type":"inject","z":"8ed637d.a0a6448","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":117.78334045410156,"y":438.00001525878906,"wires":[["46369bb9.c05d4c"]]},{"id":"46369bb9.c05d4c","type":"function","z":"8ed637d.a0a6448","name":"","func":"var buf=new Buffer(4);\nfor(var i=0;i<4;i++)\n    buf[i]=64+parseInt(Math.random()*26);\nmsg.payload=buf;\nreturn msg;","outputs":1,"noerr":0,"x":349.7832946777344,"y":465.1666259765625,"wires":[["593b8ff0.242cb8"]]},{"id":"245413cb.1c6014","type":"canconfig","z":"","channel":"vcan0","bitrate":"100000"}]

hicco...@gmail.com

unread,
Sep 28, 2017, 10:52:31 AM9/28/17
to Node-RED
Hello

I am trying to add the Can nodes into Node-Red on a RPI3.   I'm not sure how to do this? 

i already have the RPI3 configured with a can board, and I am able to send/receive data through python/socketcan.  so i know the hardware works.    

I have a lot of familiarity with canbus and how to send/read/use the data, i just need some assistance with the node-red integration.

Can you please assist me in how to get Node-Red configured ?

Thank you

Mark Setrem

unread,
Sep 28, 2017, 11:02:53 AM9/28/17
to Node-RED
In node-red 

  • Menu > manage palette
  • click on Install
  • search for canbus
  • Click on the install button next to the node
Reply all
Reply to author
Forward
0 new messages