驱动加载完成,使用ifconfig -a 可以看到两个节点
- can0: flags=128<NOARP> mtu 16
- unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 10 (UNSPEC)
- RX packets 0 bytes 0 (0.0 B)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 0 bytes 0 (0.0 B)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- device interrupt 64
-
- can1: flags=128<NOARP> mtu 16
- unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 10 (UNSPEC)
- RX packets 0 bytes 0 (0.0 B)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 0 bytes 0 (0.0 B)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- device interrupt 65
我们需要第一件事是把节点up起来
- sudo ip link set can0 type can bitrate 500000
- sudo ip link set can0 up
-
- sudo ip link set can1 type can bitrate 500000
- sudo ip link set can1 up
ifconfig 可以看到can0 can1两个节点。
can-utils是一个用于Linux的CAN(Controller Area Network)工具包,它提供了一组命令行工具,用于与CAN总线进行通信、分析和测试。这些工具非常有用,特别是在嵌入式系统、汽车领域以及需要CAN通信的应用程序中。
以下是can-utils工具包中一些常用的命令行工具:
candump: 用于监听CAN总线上的数据帧。可以用来捕获CAN消息并将其显示在终端上。
cansend: 用于向CAN总线发送CAN消息。您可以使用它来模拟CAN消息的发送。
cangen: 生成CAN消息序列,可以用于测试CAN接收器的性能。
canplayer: 从日志文件中重放CAN消息,以便重现先前的CAN通信。
cansniffer: 用于捕获CAN总线上的数据,并以更详细的格式显示CAN消息,包括时间戳等信息。
canbusload: 用于评估CAN总线的负载情况,以检查总线是否过载。
我们把两个端口短接
使用两个终端测试可以看到收到信息
cansend can0 123#1122334455667788
candump can1 //可以收到数据can1 123 [8] 11 22 33 44 55 66 77 88