Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect two VCAN ports in Linux?

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.

like image 513
viduwoy Avatar asked Dec 18 '22 19:12

viduwoy


1 Answers

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.

like image 144
oh.dae.su Avatar answered Jan 01 '23 06:01

oh.dae.su