【问题标题】:Send Message/ Inject a message with CAPL使用 CAPL 发送消息/注入消息
【发布时间】:2018-01-04 06:33:23
【问题描述】:

我是 CANoe 新手,也是 CAPL 语言。但我想问你: 如何在 ECU 的网络上使用 CAPL 发送消息。例如:我想发送一个十六进制数(这是一个 ECU 的问题),然后我想看到这个问题的响应。

我不知道我是否很清楚,但如果您有任何答案,我将不胜感激。

【问题讨论】:

  • 虽然我同意它更友好,但在stackoverflow上询问的方式通常是避免“谢谢”。它是隐含的。 “我不知道是否清楚......”也是如此。相反,您可以稍后编辑自己的问题,如果您发现有些不清楚。这样更好:它是实时的!

标签: capl canoe


【解决方案1】:

在 CAPL 中发送消息

您可以在任何事件上发送一条消息(或多条消息), 例如,按键、接收到另一条消息、接收到错误帧或计时器到期。 发送事件消息包括创建事件过程、声明要发送的消息以及在事​​件过程中发送消息。 可以将消息声明为全局变量,以便可以在任何事件过程中访问它。 如消息对象部分所示,您可以在程序中声明消息的结构,也可以使用关联的数据库。 在这个例子中,我们将在全局变量窗口中声明一个

variables 
{
  message EngineData msg1; // Defined in database
  message 0x101 msg2;      // Standard message 101 (hex)
  message 0x105x msg3;     // Extended message 105 (hex)
}

现在,要发送消息,我们只需要将以下几行之一放入事件过程中:

output(msg1); 
output(msg2);

当然,我们也可以在发送之前给消息添加数据。 EngineData 消息具有在数据库中定义的信号,但其他消息没有。因此,我们必须使用两种不同的方法向消息中添加数据。

msg1.EngSpeed.phys = 1000;
msg1.EngTemp.phys = 150;
msg1.IdleRunning = 1;
output(msg1);

msg2.DLC = 4;        // Allocate 4 data bytes in msg2
msg2.byte(0) = 0x16; // First word is 16 hex
msg2.byte(1) = 7;    // Second word is 7 decimal
output(msg2);

回复消息

on message 0x101   // This is the identifier of your response
{
  if(this.byte(0) == 0x16)
  {
    write("Response is the expected!");
  }
}

on message msg2   // This is the identifier of your response
{
  if(this.byte(0) == 0x16)
  { 
    write("Response is the expected!");
  }
}

【讨论】:

    【解决方案2】:

    您可以使用如下所示,

    variables
    {
        message BCMmsg01 msg_BCMmsg01; // declaration of message into a variable
    }
    
    on key 'z'
    {
      msg_BCMmsg01.C_AutoLockCmd = 3; // assign the value to the message
      output(msg_BCMmsg01); //send the message to the CAN bus
    }
    

    希望我澄清了你的问题。如果您需要更多说明,请告诉我。

    【讨论】:

      【解决方案3】:

      Joe 展示了消息(在本例中为十六进制值)的发送方式。如果要查看响应,则需要知道响应 ID(例如 0x62C)

      on message 0x62C    /* This is the identifier of your response */
      {
         if(this.byte(X) == 0xYY) { /* X is the byte of the response you are interested and Y the value of that byte*/
         write("Response is the expected!");
      }
      

      我希望这能回答你的问题。

      【讨论】:

        猜你喜欢
        • 2018-06-27
        • 2018-11-23
        • 1970-01-01
        • 2017-10-01
        • 1970-01-01
        • 2020-07-21
        • 1970-01-01
        • 1970-01-01
        • 2019-01-28
        相关资源
        最近更新 更多