主要内容

设置虚拟 CAN 接口

要创建虚拟 CAN 通信接口节点,请在 Raspberry Pi® 终端上执行以下步骤。

  1. 要打开 Raspberry Pi 终端,请在 MATLAB® 命令行窗口中执行以下命令。

    r=raspberrypi('<Raspberry Pi IP address>','<Raspberry Pi username>','<Raspberry Pi password>');
    r.openShell

  2. 加载 CAN 模块。

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

  3. 创建虚拟 CAN 设备。

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

  4. 使用 can-gw 模块连接两个虚拟 CAN 接口。此模块在虚拟 CAN 接口之间创建一个 PF_CAN 入口。例如,将从 vcan0 发送的所有 CAN 帧重定向到 vcan1

    sudo cangw -A -s vcan0 -d vcan1 -e
    此命令确保 vcan1 接收从 vcan0 发送的每个帧。

  5. 您可以更改源接口和目标接口,并将从 vcan1 发送的所有 CAN 帧重定向到 vcan0

    sudo cangw -A -s vcan1 -d vcan0 -e
    步骤 4 和 5 在 vcan0vcan1 之间创建双工通信。

另请参阅

| | |

主题

外部网站