如何在CANoe Capl中计算'on event'?



我想指望事件持续200ms。我在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调试器应该可以帮助您解决此类问题。

最新更新