【问题标题】:CAPL: Why am I not receiving the data bytes of a CAN message in CAPL?CAPL:为什么我没有在 CAPL 中收到 CAN 消息的数据字节?
【发布时间】:2021-09-27 04:01:43
【问题描述】:

我有一个 ECU 发送带有 2 个字节数据的 CAN 消息。我想在 CAPL 中获取这 2 个数据字节并将它们放入 2 个环境变量中。我正在开发独木舟模拟,我想使​​用这 2 个环境变量在面板中显示它们的值。

我看到 CAN 消息中的数据字节被正确接收,但是当我尝试在 CAPL 中使用这些数据字节时,它们为 0。

我有以下代码:

message CAN1.SWversion  SWversion;

on message SWversion
{
  putValue(ev_MainSW, SWversion.MainSW);
  putValue(ev_SecSW, SWversion.SecSW);
}

SWversion.MainSW 是字节(0),SWversion.SecSW 是字节(1)。我在跟踪中看到了它们的值,但在 CAPL 中它们是 0。

有什么提示吗?

Here's my trace window with the data bytes

Here's my message & signals definition in the database

Here's one of my variable definitions

【问题讨论】:

  • 我们看不到您的跟踪窗口、信号定义、环境变量定义...
  • 嗨,@M.Spiller。我已将您的建议添加到问题中。谢谢!
  • 您的环境变量的取值范围是 0x0 到 0x0。您是否尝试在 CAPL 中打印出接收到的值?
  • 我所有的变量都具有该值范围,将更大的值放入其中从来都不是问题。但是变量不是问题,我已经在 CAPL 中打印了接收到的值(CAN 消息的字节),这些值为 0。在环境变量中设置之前的值为 0。
  • 我粘贴在问题中的代码是我在 CAPL 中为该消息所拥有的一切,但不知何故,我认为我需要在使用信号的值并将它们放入之前调用一些 getData() 方法之王在变量中。我在正确的轨道上吗?

标签: can-bus capl canoe


【解决方案1】:

在您的事件处理程序中,您似乎应该访问接收到的消息,而不是全局(显然未初始化)变量:

on message CAN1.SWversion
{
  putValue(ev_MainSW, this.MainSW);
  putValue(ev_SecSW, this.SecSW);
}

【讨论】:

    【解决方案2】:

    我想通了:

    message CAN1.SWversion  SWversion;
    
    on message SWversion
    {
      putValue(ev_MainSW, SWversion.MainSW);
      putValue(ev_SecSW, SWversion.SecSW);
    }
    

    需要改成

    message CAN1.SWversion  SWversion;
    
    on message SWversion
    {
      putValue(ev_MainSW, this.byte(0));
      putValue(ev_SecSW, this.byte(1);
    }
    

    显然,您不能使用预定义的信号来访问 CAPL 中 CAN 消息中的数据。

    【讨论】:

      猜你喜欢
      • 2018-06-15
      • 2019-11-12
      • 1970-01-01
      • 2020-11-13
      • 1970-01-01
      • 2018-08-09
      • 1970-01-01
      • 1970-01-01
      • 2018-06-27
      相关资源
      最近更新 更多