0
variables
{
    mstimer T1;
    long x,y;
}

on start
{
    setTimer(T1,1); /*Timer set to 1ms*/
    x=timeNow()/100000.0; /*Getting a time stamp when i start a timer*/
}

on timer T1
{
  if(response==0)         /*Check if response is sent or a function*/ has completed successfully*/ /*CONDITION*/
  {
    cancelTimer(T1);      /*Cancel timer if response is correct*/
    y=timeNow()/100000.0; /*Getting a timestamp when i stop a timer.*/
    write("Total time taken is %d",y-x);    /*Getting the time required to complete the condition (response==0)*/
  }
  else /*Setting timer again to check the condition*/
  {
    setTimer(T1,1);
    write("Timer started again");
  }
}

当计时器设置为 1 毫秒时,值 (yx) 始终显示 1 毫秒,但如果条件在 0.7 毫秒时变为真,该怎么办。我想要条件变为真的确切时间。

我已经使用 timeNow 函数来获取时间戳。

4

5 回答 5

2

使用 CAPL 函数timeToElapse可以读取计时器的剩余时间,当它到期时,将调用在计时器 V2G 上实现的事件过程。

在帮助中,您可以找到有关 CANoe 中计时器方法的更多说明

CAPL Functions » Classes » Timer, MsTimer

关于您在原始问题中的更新。这个怎么样:

variables{
  mstimer myTimer;
  long timePoint = 0;
  int somethinghappen = 0;
}

on start{
  long firstTimeDuration, period;
  firstTimeDuration = 1000; period = 100;
  setTimerCyclic(myTimer, firstTimeDuration, period); /*Timer is set cyclical*/
  timePoint = timeNow()/100000.0; /* 
    Remember the time on measurement start, 
    which is on start always 0, so what's the reason to do this here?
  */
  write("Start time %5.3f", timePoint);
}

on timer myTimer{
  if(somethinghappen != 0){
    //you need to cancel the timer only when it was set as cyclic, see setTimerCyclic() 
    cancelTimer(myTimer); /*Cancel timer if response arrived*/
    write("Total time taken is %5.3f", timeNow()/100000.0 - timePoint); 
  }else{
    //nothing todo at the moment
  }
}

on key 'b' {//boom
  somethinghappen = 1;
}

不要忘记在测量运行时按下定义的键。

于 2018-01-02T15:02:11.760 回答
1

正如许多人已经指出的那样,我相信您使用不正确on timer。从 Vector 知识库,

您可以在 CAPL 中定义时间事件。当这个事件发生时,即当某个时间段过去时,相关的on timer过程被调用。

从我在这里看到的情况来看,通过在内部执行布尔检查on timer,您将始终在计时器结束时读取当前经过的时间。如果由于某种情况发生而要过早退出计时器,我会建议一个完整的解决方法。您是否尝试过设置系统变量?

于 2018-02-13T13:53:53.830 回答
1

如果您需要测量小于 1ms 单位的时间,请使用 TimeNowNS() 函数(纳秒)。基本上用 TimeNow() 和 TimeNowNS() 替换您的代码,并将使用的变量调整为双倍,以便您记录的时间戳将正确匹配。

于 2018-09-21T14:08:31.473 回答
0

我看不到任何可以访问的价值。在这里,你正在做布尔检查。请澄清你的问题。

于 2017-12-27T09:14:13.050 回答
0
/* Timer values depend on the value that u gave in settimer() API, This is one of the way you can know the value of timer*/
Variable
{
mstimer t1;
timer t2;
}
on Start
{
Settimer(t1,10);/*waits for 10 ms and then goes to timer t1*/
}

on timer t1
{
settimer(t2,10);/*waits for 10 s and then goes to timer t2, so the value of timer t1 = 10s*/
}

on timer t2
{

}

/*This is what i understood from what you asked. For further clarification give some more explanation on what you are asking*/
于 2018-01-07T10:17:34.907 回答