繁体   English   中英

如何在 CANoe Capl 中指望“事件”?

[英]How to count 'on event' in CANoe Capl?

我想依靠事件 200 毫秒。 我在 CANoe Capl 中尝试使用此代码,但效果不佳。 我不知道是什么问题。 请帮帮我。

主活动.Capl

variables
{ 
  int timerConditionChecker = 0;
  int lockStatusMonitor = 0;

  mstimer conutCheckTimer;
}

on timer conutCheckTimer
{
  //do nothing
}

on sysvar_update sysvar::Frame2
{
    if(timerConditionChecker == 0)
    {
      lockStatusMonitor++;
      timerConditionChecker = 1;
      setTimer(conutCheckTimer, 500);
    }
    else if(timerConditionChecker == 1)
    {
      if(timeToElapse(conutCheckTimer) > 200)
      {
        timerConditionChecker = 2;
      }
      else
      {
        lockStatusMonitor++;
      }
    }
    else if(timerConditionChecker == 2)
    {
      timerConditionChecker = 3;
      Write("lockStatusMonitorCount = %d",lockStatusMonitor);
    }
    else{}
}

这个怎么样(我主要使用你的变量名):

variables
{ 
  int lockStatusMonitor = 0;

  mstimer conutCheckTimer;
}

on timer conutCheckTimer
{
  // Is called after 200ms and will output how often the sysvar was updated within these 200ms
  Write("lockStatusMonitorCount = %d",lockStatusMonitor);
}

on sysvar_update sysvar::Frame2
{
    if(isTimerActive(conutCheckTimer))
    {
        // In case the 200ms have already started, just count
        lockStatusMonitor++;
    }
    else {
        // Timer is not yet active, so start counting for the next 200ms now
        lockStatusMonitor = 0; // or = 1 depending on whether your use case
        setTimer(conutCheckTimer, 200);
    }
}

除此之外,使用 CAPL 调试器应该可以帮助您解决此类问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM