2

I have a CAPL test code that controls the start of CAN signal sending. My goal is to delay the start of the sending process. My idea to do this is via a setTimer() function in combination with isTimerActive().

In general my code looks the following:

main() {   
CANstart();
function_2();
function_3();   
}

CANstart() {    
  SetTimer(Delay, 5000); //Timer initialization, set to be 5000ms

  while (isTimerActive()==1) {
    // this while loop avoids that the code is proceding while the settimer exception is being called and executed
  }

  StartCANTransmitting(); // After this function, jump back to main and proceed with function_2   
}

on timer Delay {
  // Do nothing, just wait   
}

The program code above lead to being stuck at that point, CANoe does not response and the only way I can end the simulation is via taskmanager.

  • Further examination from my side lead to the conclusion that the timer need more time to process and is not executed at all.
  • Without the isTimerActive() function, the program code does not wait for the timer to finish and there is no delay at all. Seems like the code runs through without waiting for the exception.
  • Seems like CAPL handles loops very bad.

I check out stackoverflow and the following forum posts talk about very similar issues that I have without offering any working solutions:

CAPL Programming usage of Timer as a delay

Are timers running, while loops are active?

Delay function in CAPL apart from testwaitfortimeout()

Johann Diep
  • 33
  • 1
  • 1
  • 6
  • You are using main, which means that you are probably writing a CAPL test node, right? In this case, `TestWaitForTimeout` is the way to go. CAPL timers, as you used, are more for simulation nodes and the like, where things are event based. Can you please show how you send the CAN message and in which way exactly it goes wrong? – Torsten Knodt Sep 14 '21 at 16:14

2 Answers2

0

I see a great deal of issues with your code. It actually does not feel like code at all, but more like pseudo-code. Does it compile on your CAPL browser?

main() {   
CANstart();
function_2();
function_3();   
}

If this is a function declaration, then it is missing both a type and a return value. In addition, when are you expecting main() to be executed?

The same applies to:

CANstart()

Let us make a step back. You need to delay the beginning of can transmitting. If you need to do so because you have code outside CANalyzer/CANoe running, then I suggest you call the application via command line (refer to the guide for more help).

If you need, however, to have blocks running in your setup configuration, like a Replay block, a Loggin block or whatever, I suggest you to do the following:

variables {
    /* define your variables here. You need to define all messages you want to send and respective signal values if not defaulted */
    message 0x12345678 msg1;   // refer to CAPL guide on how to define message type variables
    msTimer delay;
    msTimer msgClock1;
}

on start {
    /* when you hit the start measurements button (default F9) */
    setTimer(delay, 5000);   // also note your syntax is wrong in the example
}

on timer delay {
    /* when timer expires, start sending messages */
    output(msg1);    // send your message
    setTimer(msgClock1,250);    // set timer for cyclic message sending
}

on timer msgClock1 {
    /* this mimicks the behaviour of a IG block */
    setTimer(msgClock1,250);    // keep sending message
    output(msg1)
}

Does this achieve your goal? Please feel free to ask for more details.

Daemon Painter
  • 3,208
  • 3
  • 29
  • 44
0

It appears that you have a problem with the while (isTimerActive()==1) { statement.

CAPL function int isTimerActive requires the parameters timer or mstimer variable and return values 1, if the timer is active otherwise 0.

You can check if the timer is active and the time to elapse in the following way.

timer t;
write("Active? %d", isTimerActive(t)); // writes 0
setTimer(t, 5);
write("Active? %d", isTimerActive(t)); // writes 1
write("Time to elapse: %d",timeToElapse(t)); // Writes 5

try adding the parameter timer at while (isTimerActive(Delay)==1) {

I would not suggest using the while statement instead you can use the timer directly to call the function StartCANTransmitting() and your Main() should be MainTest()

void MainTest()
{
   TestModuleTitle("Sample Tests");
   TestModuleDescription("This test module calls some test cases to demonstrate ");
   CANstart();
   if (TestGetVerdictLastTestCase() == 1)
      Write("CANstart failed.");
   else
      Write("CANstart passed.");
}

testcase CANstart() {   
  // add info block to test case in report  
  TestReportAddMiscInfoBlock("Used Test Parameters");
  TestReportAddMiscInfo("Max. voltage", "19.5 V");
  TestReportAddMiscInfo("Max. current", "560 mA");
  TestReportAddMiscInfo("StartCANTransmitting");

  SetTimer(Delay, 5000); //Timer initialization, set to be 5000ms
}

on timer Delay {
  StartCANTransmitting();   
}
Om Choudhary
  • 492
  • 1
  • 7
  • 27