栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Linux CAN 驱动测试

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux CAN 驱动测试

一、查看can设备是否被识别

执行#ifconfig -a

root@scm801:/home/sysadm# ifconfig -a
can0: flags=193  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 17  bytes 130 (130.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3  bytes 102 (102.0 B)
        TX errors 14  dropped 4 overruns 0  carrier 4  collisions 0
        device interrupt 21  

can1: flags=193  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 3  bytes 22 (22.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1  bytes 18 (18.0 B)
        TX errors 2  dropped 1 overruns 0  carrier 1  collisions 0
        device interrupt 22  

可以看到本机上有can0和can1两个can设备。

二、安装linux下can测试工具(Ubuntu下安装包can-utils_2018.02.0-1_armhf.deb)

    执行#dpkg -i can-utils_2018.02.0-1_armhf.deb

root@scm801:/home/sysadm# dpkg -i can-utils_2018.02.0-1_armhf.deb 
Selecting previously unselected package can-utils.
(Reading database ... 13686 files and directories currently installed.)
Preparing to unpack can-utils_2018.02.0-1_armhf.deb ...
Unpacking can-utils (2018.02.0-1) ...
Setting up can-utils (2018.02.0-1) ...

三、Can测试

1、本机回环测试

    #ifconfig can0 down      //can0总线关闭,关闭后才能设置参数

   #ip link set can0 type can bitrate 500000 loopback on //配置can频率500khz,本地回环开

  #ip link set canx type can tq 200 prop-seg 6 phase-seg1 6 phase-seg2 2 sjw 1  //设置总线  帧参数:TQ-位单位时间SJW-重新同步跳跃宽度PBS-phase-seg-相位缓冲PTS-prop-seg-传播时间缓冲

   #ip link set can0 up  //重新启动can0总线

 #ip –details link show can0 //查看配置完后can0总线信息;

 #candump can0 &      //can0后台接收

 #cansend can0 123#112233445566 

//向can0口发送标准帧,帧id是0x123,数据是0x11 0x22 0x33 0x44 0x55 0x66

# can0  123   [6]  11 22 33 44 55 66     //发送的打印信息
  can0  123   [6]  11 22 33 44 55 66   //本地回环接收的打印信息

2、本机can0和can1口测试

1)将can0的can_H和can_L分别连接can1的can_H和can_L

2)配置can0

#ifconfig can0 down      //can0总线关闭,关闭后才能设置参数

#ip link set can0 type can bitrate 500000 loopback off //本地回环关

#ip link set can0 up   //重新启动can0总线

3)配置can1

#ifconfig can1 down      //can0总线关闭,关闭后才能设置参数

#ip link set can1 type can bitrate 500000 loopback off //本地回环关

#ip link set can1 up   //重新启动can1总线

#candump can1 &      //can1后台接收

#cansend can0 123#112233445566   //通过can0发送

  can1  123   [6]  11 22 33 44 55 77   //can1收到数据

3、本机can0与外接can盒测试

 1)安装can盒USBCAN-2E-U驱动程序

2)将can盒的can0的can_H和can_L分别连接can0的can_H和can_L

3)打开CANTest测试软件,选择设备为USBCAN-2E-U,选择第0路can,设置波特率为500k,确

定并启动can

4)板卡上启动can0接收

#candump can0  &      //can0后台接收

5)选择帧类型,填写帧id,数据,点击发送

 板块收到can盒数据,

 同样,板块上通过can0发送数据

  # cansend can0 123#112233445577,can盒也能收到

自此,linux can 驱动测试完成。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/826818.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号