0
votes

I am running a script in CAPL where I am supposed to notice a change in the value of a signal (for example: signal B) coming from the ECU. At the start of the timer, I change the value of another signal (for example: signal A) and sent it to ECU over CAN Bus. While the timer is running, I want to see the changed value of signal B coming from ECU as a response to the changed value of signal A. After the timer has run out, I want to reset the signal A back to its original value.

*Note: I have called the different signals as Signal A and Signal B only for understanding the question more clearly

Signal A changes the value from 2 to 0. Signal B has original value of 61, and the changed value can be any number between 0-60. Timer runs for 4 seconds. I am using while loop and command (isTimerActive(timer)==1), to check for the change in the value of signal B when the timer is running.

Below is the attached Code ->

variables
{
 msTimer Execute;
}

on key 'c'
{
 setTimer(Execute,4000);
 Write("Test starts");
 SetSignal(Signal A, 2);
while (isTimerActive(Execute)==1)
{
 if ($Signal B != 61)
    {
     Write("Test pass");
     }
    else
    {
      Write("Test fail");
    }
}
}

on timer Execute
{
  write("Test over");
  setSignal(Signal A, 0);
}

I am executing this code and the value of signal A changes to 2 but there's no change in the value of signal B. I am using the (isTimerActive (timer) ==1) in the while loop, is it the correct command for my problem? Also, when I run (isTimerActive (timer) ==1), CANoe becomes inactive and I have to stop CANoe using Task manager.

Any ideas how can I correct my code and get the desired response?

Thanks and Best

1

1 Answers

0
votes

CAPL is event-driven. Your only choice is to react on events by programming event handlers, i.e. the functions starting with on ....

During execution of an event handler, the system basically blocks everything until the event handler has finished. Literally nothing else happens, no sysvars change, no signals change, no timers expire, no bus messages are handled, and so on.

For test-modules and -units the story is a little bit different. There you have the possibility to wait during execution of your code using the various testWaitFor... methods.

With your current implementation of on key ā€˜cā€˜you basically block the system, since you have an while loop there waiting for an Timer to expire.

As stated above, this blocks everything and you have to kill CANoe.

Fortunately changes of signals are also events that can be handled.

Something like this should do:

Remove the while block and instead add another event handler like this:

on signal SignalB
{
  if(isTimerActive(Execute))
  {
    if ($SignalB != 61)
    {
      Write("Test pass");
    }
    else
    {
      Write("Test fail");
    }
  }
}

The code is called when SignalB changes. It then checks whether the Timer is still running and checks the value of the signal.

Instead of $SignalB inside of the handler you can also write this.

In an event handler this is always the object that has caused the event.