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");
}
}
the value (y-x) always shows 1ms as the timer is set to 1ms, but what if the condition has become true at 0.7ms. I wanted the exact time at which the condition became true.
I have used timeNow function to get the timestamps.
As many have already pointed out, I believe you are using on timer
uncorrectly.
From Vector knowledge base,
You can define time events in CAPL. When this event occurs, i.e. when a certain period of time elapses, the associated
on timer
procedure is called.
From what I see here, by performing your boolean check inside on timer
, you will always read the current time elapsed at the end of the timer. If you want to exit the timer prematurely due to a certain condition happening, I would suggest a complete workaround. Have you tried setting a system variable?