Main Content

Setup Virtual CAN Interface

To create virtual CAN communication interface nodes, perform these steps on a Linux® shell on NVIDIA® hardware.

  1. To open a Linux shell, execute these commands on the MATLAB® Command Window.

    hwObj = jetson;
    openShell(hwObj);
    

  2. Load CAN modules

    sudo modprobe vcan # Virtual CAN Modules 
    sudo modprobe can-gw # CAN Gateway module required for connecting two virtual CAN Nodes

  3. Create virtual CAN device

    sudo ip link add <canInterfaceName> type vcan # Ex : sudo ip link add vcan0 type vcan

  4. Connect two virtual CAN interfaces using can-gw module. A virtual connection between two virtual CAN interfaces is established using can-gw module. This module creates a PF_CAN gateway between the virtual CAN interfaces. For example, redirect all the CAN frames sent from vcan0 to vcan1.

    sudo cangw -A -s vcan0 -d vcan1 -e
    This command ensures that vcan1 receives every frame sent from vcan0.

  5. You can change the source and destination interfaces and redirect all the CAN frames sent from vcan1 to vcan0.

    sudo cangw -A -s vcan1 -d vcan0 -e
    Steps 4 and 5 ensures a duplex communication between vcan0 and vcan1.

See Also

Blocks

Related Topics