设置虚拟 CAN 接口
要创建虚拟 CAN 通信接口节点,请在 Raspberry Pi® 终端上执行以下步骤。
要打开 Raspberry Pi 终端,请在 MATLAB® 命令行窗口中执行以下命令。
r=raspberrypi('<Raspberry Pi IP address>','<Raspberry Pi username>','<Raspberry Pi password>'); r.openShell加载 CAN 模块。
sudo modprobe vcan # Virtual CAN Modules sudo modprobe can-gw # CAN Gateway module required for connecting two virtual CAN Nodes
创建虚拟 CAN 设备。
sudo ip link add <canInterfaceName> type vcan # Ex : sudo ip link add vcan0 type vcan
使用
can-gw模块连接两个虚拟 CAN 接口。此模块在虚拟 CAN 接口之间创建一个PF_CAN入口。例如,将从vcan0发送的所有 CAN 帧重定向到vcan1。此命令确保sudo cangw -A -s vcan0 -d vcan1 -e
vcan1接收从vcan0发送的每个帧。您可以更改源接口和目标接口,并将从
vcan1发送的所有 CAN 帧重定向到vcan0。步骤 4 和 5 在sudo cangw -A -s vcan1 -d vcan0 -e
vcan0和vcan1之间创建双工通信。
另请参阅
Enable and Configure Raspberry Pi for SPI and CAN Communication Using MCP2515 CAN Controller | CAN Transmit | CAN Receive | CAN 属性
主题
- Transmit and Receive Data Using Raspberry Pi CAN Blocks
- Monitor Engine RPM Using Raspberry Pi CAN Blocks