今天搭建了CANoe与金溢的obu can连接的环境问题。遇到了一个让人不解的问题。
can0起不来,于是怀疑波特率不匹配,使用调不了。
Linux 设置波特率
ifconfig can0 down /*关闭CAN0*/
ip link set can0 type can bitrate 250000 /*设置CAN0 250K波特率*/
ifconfig can0 up /* 开启CAN0*/
---------------------
sudo ip link set can0 type can bitrate 500000 /*设置CAN0 500K波特率*/
sudo ip link set can0 up
问题的现象:
[root@genvict ~]# ifconfig can0 up
ifconfig: SIOCSIFFLAGS: Invalid argument
[root@genvict ~]# link can 500000 bitrate type can0 set ip
-sh: link: command not found
[root@genvict ~]# ip link set can0 type can bitrate 500000
ip: either "dev" is duplicate, or "type" is garbage
[root@genvict ~]# ifconfig can1 up
ifconfig: SIOCSIFFLAGS: Invalid argument
[root@genvict ~]# 500000bitratecantypecan0setlinkipsudo
-sh: 500000bitratecantypecan0setlinkipsudo: command not found
[root@genvict ~]#
Socket error Event: 32 Error: 10053.
Connection closing...Socket close.
问题解决:
后来发现:根目录下有一个 production_test_tools_wbl20b_v1.2可执行文件,运行了这个设备自带的调试工具文件后,发现can起不来的问题解决了。
由于可执行文件是一个二进制文件,不好直接阅读,只能从中读取搜索一些关键字信息。
使用obu向Canoe发送消息:
[root@genvict ~]# cansend can0 0x88 #通过can来发送消息
interface = can0, family = 29, type = 3, proto = 1
[root@genvict ~]# cansend can0 -i 0x44 0x8 0x9 0x6 --loop=20 #向can0 发送数据,可以传8个十六进制的数
can0 向 interface=can0发送数据
-i 0x44 消息的ID号为44
0x8 0x9 0x6 三个数据可以由最多8个字节组成,以空格分隔的列表形式给出
--loop=20 循环发送20次
从canoe上看到接收到的发送的消息:
用法: cansend [<can-interface>] [Options] <can-msg>
<can-msg>可以由最多8个字节组成,以空格分隔的列表形式给出
选项:
interface = can0, family = 29, type = 3, proto = 1
[root@genvict ~]# cansend --help
Usage: cansend [<can-interface>] [Options] <can-msg>
<can-msg> can consist of up to 8 bytes given as a space separated list
Options:
-i, --identifier=ID CAN Identifier (default = 1)
-r --rtr send remote request
-e --extended send extended frame
-f, --family=FAMILY Protocol family (default PF_CAN = 29)
-t, --type=TYPE Socket type, see man 2 socket (default SOCK_RAW = 3)
-p, --protocol=PROTO CAN protocol (default CAN_RAW = 1)
-l send message infinite times
--loop=COUNT send message COUNT times
-v, --verbose be verbose
-h, --help this help
--version print version information and exit
candump #查看can的接
[root@genvict ~]# candump --help
Usage: candump [<can-interface>] [Options]
Options:
-f, --family=FAMILY protocol family (default PF_CAN = 29)
-t, --type=TYPE socket type, see man 2 socket (default SOCK_RAW = 3)
-p, --protocol=PROTO CAN protocol (default CAN_RAW = 1)
--filter=id:mask[:id:mask]...
apply filter
-h, --help this help
-o <filename> output into filename
-d daemonize
--version print version information and exit
接收测试,接收测试软件发送的帧:
# ./candump can0
interface = can0, family = 29, type = 3, proto = 1
<0x00000002> [8] 70 01 02 03 04 05 06 07
[root@genvict ~]# canecho --help
Usage: canecho <can-interface> [<can-interface-out>] [Options]
Send all messages received on <can-interface> to <can-interface-out>
If <can-interface-out> is omitted, then <can_interface> is used for sending
Options:
-f, --family=FAMILY Protocol family (default PF_CAN = 29)
-t, --type=TYPE Socket type, see man 2 socket (default SOCK_RAW = 3)
-p, --protocol=PROTO CAN protocol (default CAN_RAW = 1)
-v, --verbose be verbose
-h, --help this help
--version print version information and exit
来源:https://blog.csdn.net/usstmiracle/article/details/98883805