在两条 CAN 总线之间设置网关(Setting Up a Gateway between Two CAN Busses)

在两条 CAN 总线之间设置网关 (Setting Up a Gateway between Two CAN Busses)

KB 编号: KB0011376

分类: CANoe

发布日期: 2026-02-16

阅读量: 9312

来源: https://support.vector.com/kb?id=kb_search\&spa=1\&query=KB0011376


问题 (Question):

如何在两条 CAN 总线 (CAN bus) 之间设置网关 (gateway)?

答案 (Answer):

网关 (gateway) 用于将报文 (message) 从一条总线 (bus) 发送到另一条总线,反之亦然。可以对信号 (signal) 进行修改 (manipulation),有时信号会被放在不同的报文中发送。一个常见的用例是将新的(下一代)ECU 集成到现有的 CAN 总线 (CAN bus) 中,以替换旧版本的 ECU。

要设置网关 (gateway),请按以下步骤操作:

在仿真设置 (simulation setup) 中为第一个 CAN 网络 (CAN network) 添加一个节点 (node)。分配一个 .CAN 文件名并编辑它。以下是一个示例:

capl 复制代码
on message CAN1.*
{
  message CAN2.* m;
  if(this.DIR==RX)        // if it is a received frame
  {
   if(this.CAN==1)
   {
    m=this;
    output(m);      // send it to the other channel
   }
  }
}

on message CAN2.*           
{
 message CAN1.* m;
 if(this.DIR==RX)        // if it is a received frame
 {
  if(this.CAN==2)
  {
   m=this;
   output(m);      // send it to the other channel
  }
 }
}

CAN2

CAN2)。在两个网络中,该节点现在应该都带有桥接标志 (bridge sign)(表示这是一个网关 (gateway))。

CAN1

on message...

为包含该信号的报文编写 on message... 事件过程 (event procedure),例如:

capl 复制代码
on message CAN1.0x123
{
 message CAN2.0x123 m;
 // this is an example for a message that will be manipulated before it is sent on CAN2
 if (this.DIR==RX)           // if this message is received
 {
  if(this.CAN==1)
  {
   m=this;
   m.Byte(0)=0x17;     // for example manipulate the first byte
   m.Byte(1)=0x17;     // for example manipulate the second byte
   // you can use signal-based access as well:  m.SignalName = ....
   output(m);
  }
 }
}

on message CANx.xxx

相应地修改 on message CANx.xxx 语句。

对于更复杂的网关 (gateway),你可能需要将从一个总线 (bus) 接收到的信号 (signal) 以不同的 CAN ID 在另一个总线上通过报文 (message) 发送出去。在这种情况下,你需要将接收到的信号值存储起来,以便稍后在定时器触发 (timer-triggered) 的事件过程 (event procedure) 中发送。


📎 本文 PDF 原文: KB0011376_Setting_Up_a_Gateway_between_Two_CAN_Busses.pdf

相关推荐
CappuccinoRose1 个月前
Rust学习文档(四)
开发语言·后端·学习·算法·rust·vector·map
努力中的编程者2 个月前
STL-vector的模拟实现
开发语言·c++·算法·stl·vector
j7~2 个月前
【C++】STL--Vector容器--拆析解剖Vector的实现以及Vector的底层详解(1)
开发语言·c++·vector·迭代器失效·迭代器的使用
weixin_461769403 个月前
通过数组和队列构造二叉树方法(用于算法测试),C++ vector不能直接使用null
数据结构·c++·算法·vector·nullptr·null
十五年专注C++开发3 个月前
std::vector<T>到QVector<T>的数据复制方案
c++·vector·iterator模式·qvector
hh.h.3 个月前
昇腾CANN atvc 仓:Vector 算子模板库——Vector 单元的算子开发
vector·算子·昇腾·cann
IT大白鼠3 个月前
Vector、Fluentd、Fluent Bit — 日志采集与传输,高性能替代方案选择指南
vector·fluentd·fluent bit
少司府3 个月前
C++基础入门:vector深度解析(七千字深度剖析)
c语言·开发语言·数据结构·c++·容器·vector·顺序表
alwaysrun4 个月前
Zig之标量、向量与SIMD
vector·向量·simd·zig