CANoe与金溢的obu can连接的环境问题 Cifconfig can0 up 失败 设置波特率失败

本文记录了在搭建CANoe与金溢的OBU CAN连接环境中遇到的can0无法启动问题,并分享了解决方案。通过运行特定的可执行文件和正确的波特率设置命令,成功解决了连接问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天搭建了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起不来的问题解决了。

由于可执行文件是一个二进制文件,不好直接阅读,只能从中读取搜索一些关键字信息。

 

惊不惊喜意不意外?这就解决了?什么垃圾博主!

 

 

 

 

 

 

 

我分析了上面的文件,文件里执行了一句命令,就是设置了波特率

网上很多设置波特率的命令是不生效的:

最后放大招了!!!!!!!!!!!!

用这行命令设置波特率:

canconfig can0 bitrate 500000    /*设置CAN0   500K波特率*/

 

使用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

### 设置 CANOECAN FD 的波特率 在 Vector Informatik 提供的工具 CANoe 中配置 CAN FD 总线参数时,设置 CAN FD 波特率是一个重要环节。对于 CAN FD 而言,存在两种不同的波特率:仲裁阶段 (Arbitration phase) 和数据阶段 (Data phase)[^1]。 为了设定这两种波特率,在 CANoe 配置界面中需遵循如下方法: #### 打开总线属性对话框 通过导航栏中的“Network Configuration”,找到对应的 CAN 接口并双击进入其属性页面。 #### 进入 CAN FD 特定选项卡 切换到专门针对 CAN FD 参数调整的标签页下操作。 #### 设定仲裁位速率 在此处输入期望用于消息初始传输部分——即 ID 及控制字段解析过程所使用的比特率数值;该值通常较高以确保优先级判断迅速完成[^2]。 #### 数据位速率定义 紧接着指定当转入数据帧主体发送时应采用的速度等级;此速度可以显著高于前者以便加快有效载荷传递效率[^3]。 ```cpp // 示例代码展示如何利用 API 函数来更改 CAN FD 通信对象的两个不同阶段的波特率 void SetCanFdBaudRate(CAN_CHANNEL channel, uint32_t arbitrationBaudrate, uint32_t dataBaudrate){ // 假设函数原型已声明且库文件已导入 can_set_bittiming(channel, CAN_FD_BITTIMING_ARB, &arbitrationBaudrate); can_set_bittiming(channel, CAN_FD_BITTIMING_DATA, &dataBaudrate); } ``` 请注意实际应用过程中还需考虑硬件支持情况以及网络拓扑结构等因素的影响,合理规划才能达到最佳性能表现。
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

aFakeProgramer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值