Setup Virtual CAN Interface
To create virtual CAN communication interface nodes, perform these steps on Raspberry Pi® terminal.
To open a Raspberry Pi terminal, execute these commands on the MATLAB® Command Window.
r=raspberrypi('<Raspberry Pi IP address>','<Raspberry Pi username>','<Raspberry Pi password>'); r.openShellLoad CAN modules.
sudo modprobe vcan # Virtual CAN Modules sudo modprobe can-gw # CAN Gateway module required for connecting two virtual CAN Nodes
Create virtual CAN device.
sudo ip link add <canInterfaceName> type vcan # Ex : sudo ip link add vcan0 type vcan
Connect two virtual CAN interfaces using the
can-gwmodule. This module creates aPF_CANgateway between the virtual CAN interfaces. For example, redirect all the CAN frames sent fromvcan0tovcan1.This command ensures thatsudo cangw -A -s vcan0 -d vcan1 -e
vcan1receives every frame sent fromvcan0.You can change the source and destination interfaces and redirect all the CAN frames sent from
vcan1tovcan0.Steps 4 and 5 creates a duplex communication betweensudo cangw -A -s vcan1 -d vcan0 -e
vcan0andvcan1.
See Also
Enable and Configure Raspberry Pi for SPI and CAN Communication Using MCP2515 CAN Controller | CAN Transmit | CAN Receive | CAN properties
Topics
- Transmit and Receive Data Using Raspberry Pi CAN Blocks
- Monitor Engine RPM Using Raspberry Pi CAN Blocks