5

I have set up two vcan devices and I want to treat them as if they were connected together. I want to be able to use can-utils candump to listen on one line, and send can messages from the other. How can I do that without a physical device?

For clarification, I am writing software to communicate over CAN which I am already capable of, but to facilitate the actual data gathering and further development, I need two can enabled devices to communicate with each other. While a simple solution in the real world, solved by physically connecting devices together, I need a programmatic solution that will work on the computer.

0

2 Answers 2

14

Add the can gateway kernel module:

sudo modprobe can-gw

Then create gateway rules via cangw, which comes with can-utils, for the respective interfaces.
For example, for routing messages from vcan0 to vcan1:

sudo cangw -A -s vcan0 -d vcan1 -e 

and the other way around:

sudo cangw -A -s vcan1 -d vcan0 -e

Now you will be able to see all messages sent on vcan0 also on vcan1 and vice versa.

3
  • This works perfectly! Do you know where the documentation is for can-gw?
    – viduwoy
    Commented Jan 22, 2019 at 16:39
  • I am not sure, if a documentation exists. If you enter cangw without arguments you get details on the usage and some examples.
    – oh.dae.su
    Commented Jan 22, 2019 at 18:27
  • works perfectly on BBB, connecting can0 and can1 cangw -A -s can0 -d can1 -e Won't let you set this rule if modprobe can-gw not set Commented May 11, 2021 at 12:35
0

I wanted to add that you could also connect a virtual can interface with a real one.

For example if you have a simulated system using virtual cans and want to connect actual CAN Hardware you could connect those with

sudo cangw -A -s vcan0 -d can0 -e and sudo cangw -A -s can0 -d vcan0 -e

Not the answer you're looking for? Browse other questions tagged or ask your own question.