3

I have been writing a CAPL script that would send message on each channel (2 no's) after a certain delay. The following delay i want to generate using SetTimer() and mstimer::isRunning function. I can use setTimer function but I dont know how to use mstimer::isRunning. The code is shown below:

    Variables{
          message * temp = {DLC=8};
          mstimer timer1;
    }
    on timer timer1{
        //Do nothing
    }
    onstart{

    for(noofChannel=1;noofChannel<=2;noofChannel++){
        settimer(timer1,100);
        temp.CAN = noofChannel;
        temp.ID = 0xAA;
        While (mstimer::isrunning)==0 // I need to write this right.
        { //wait for timer to expire}
        Output(temp);

    }
Yash Vardhan
  • 67
  • 1
  • 1
  • 5
  • 2
    When asking stuff about CAPL, it is important to specify if you're in "Simulation" or "Test" mode. Some functionalities are made available/disabled depending on what kind of script you're writing. – PlamZ Jun 10 '15 at 19:28
  • Thanks for the advice! I was using Simulation mode, But I needed a solution compatible to both simulation and Realtime. – Yash Vardhan Jun 12 '15 at 03:22

3 Answers3

1

Instead of mstimer::isrunning use isTimerActive() method. isTimerActive() returns 1 if timers is running and 0 if it is expired. So your code will look like:

on start{

    for(noofChannel=1;noofChannel<=2;noofChannel++){
        settimer(timer1,100);
        temp.CAN = noofChannel;
        temp.ID = 0xAA;
        While (isTimerActive(timer1) == 1)  
        { //wait for timer to expire}
        }
        Output(temp);

      }
    }

But I would not recommend doing this. Instead of looping in on start, you can ouput 2nd message through onTimer

on start{
            temp.CAN = 1;
            temp.ID = 0xAA;
            Output(temp);
            settimer(timer1,100);
        }

on timer timer1{
    temp.CAN = 2;
    Output(temp);
}

If you want to keep it generic i.e. not restricting to 2 channels, you can take a variable and increment it in timer.

Swanand
  • 4,027
  • 10
  • 41
  • 69
0

I asked Vector for the same question and they answered it something like this: “msTimer.isRunning” gives us status of Timer, whether timer running or not The usability is mentioned below:

      on timer myTimer
      {
         write("Running Status %d",myTimer.isRunning());
      }

" timeToElapse() " function can also be used for the following case. Syntax:

      timer t;
      setTimer(t,5);
      write("Time to elapse: %d",timeToElapse(t)); // Writes 5
Yash Vardhan
  • 67
  • 1
  • 1
  • 5
0
/*Solution on how timer works*/

variables
{
mstimer t1,t2;/*millisec timer*/
timer t3;/*sec timer*/
}
on timer t1
{
settimer(t2, 10);/*wait in timer t1 for 10ms and then goes to timer t2*/
}
on timer t2
{
settimer(t3, 10);/*wait in timer t2 for 10ms and then goes to timer t3*/
}
on timer t3
{
settimer(t4, 10);/*wait in timer t3 for 10sec and then goes to timer t4*/
}
on timer t4
{
settimer(t1, 10);/*wait in timer t4 for 10sec and then goes to timer t1*/
}

on start()
{
settimer(t1,10);/*waits here for 10ms and then goes to timer t1*/
}
Prakash
  • 27
  • 1
  • 9