Skip to main content

前言

本页为 CAN 查询、设置、发送、接收 can0 节点的简单使用

CAN使用

  1. 查询当前网络设备
$ 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 71

......
  1. CAN启动:
# 关闭CAN:
$ ip link set can0 down
# 设置比特率500KHz:
$ ip link set can0 type can bitrate 500000
# 打印can0信息:
$ ip -details -statistics link show can0
# 启动CAN:
$ ip link set can0 up
  1. CAN发送:
# 发送 标准帧,数据帧
$ cansend can0 123#DEADBEEF
# 发送 标准帧,远程帧
$ cansend can0 123#R
# 发送 扩展帧,数据帧
$ cansend can0 00000123#12345678
# 发送 扩展帧,远程帧
$ cansend can0 00000123#R
  1. CAN接收:
$ candump can0