CAN总线设备接口
CAN总线的设备驱动接口提供一个通用的接口来建立,设置和监控CAN网络设备。用户可以配置CAN设备,如同配置网络接口一样来通过iproute2工具包设置波特率等。
设置波特率 在开始使用CAN网络设备之前,你必须先配置波特率,例:
ip link set canX up type can bitrate 125000
X是您要配置的CAN接口序号
启用和停用CAN网络设备 和其它类型的网络类似,您可以用ifconfig命令来启用或停用CAN接口 启用:
ifconfig canX up
停用:
ifconfig canX down
更多信息请参考Linux内核文档:Documentation/networking/can.txt.
CAN设备测试程序
The CAN support is based on the SocketCAN stack. For more information and source code about this project, refer to http://elinux.org/CAN_Bus and https://github.com/linux-can/.
Build the package dey-examples-can in your Yocto project to install the test application can_test.
To display the application syntax run:
can_test –help
- Examples
To send an 8-bit CAN message to node can0 with ID 0x12 and the data pattern 0x65:
can_test -l 1 -b 8 -d can0 -i 0x12 -p 0x65 -m
To receive a similar message:
can_test -l 1 -b 8 -d can0 -i 0x12 -p 0x65