linux CAN操作命令

1.sudo modprobe vcan
加载虚拟can模块

2.sudo ip link add dev vcan0 type vcan
添加vcan0网卡

3.ifconfig -a 
可以查到当前can网络 can0 can1,包括收发包数量、是否有错误等等

//ip link set can0 type can --help
4.ip link set can0 up type can bitrate 800000
设置can0的波特率为800kbps,CAN网络波特率最大值为1Mbps

5.ip link set can0 up type can bitrate 800000 loopback on
设置回环模式,自发自收,用于测试是硬件是否正常,loopback不一定支持

6. ip link set can0 down
关闭can0 网络

7.cansend can0 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88
发送默认ID为0x1的can标准帧,数据为0x11 22 33 44 55 66 77 88
每次最大8个byte

8.cansend can0 -i 0x800 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 -e
-e 表示扩展帧,CAN_ID最大29bit,标准帧CAN_ID最大11bit 
-i表示CAN_ID

9. cansend can0 -i 0x02 0x11 0x12 --loop=20
--loop 表示发送20个包

10.candump can0
接收CAN0数据

参考:
http://processors.wiki.ti.com/index.php/AM335X_DCAN_Driver_Guide
http://elinux.org/Bringing_CAN_interface_up

  • 3
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值