2

我有一个控制 CAN 信号发送开始的 CAPL 测试代码。我的目标是延迟发送过程的开始。我的想法是通过 setTimer() 函数与 isTimerActive() 结合使用。

一般来说,我的代码如下所示:

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   
}

上面的程序代码导致卡在那个点,CANoe 没有响应,我可以结束模拟的唯一方法是通过任务管理器。

  • 从我这边进一步检查得出的结论是计时器需要更多时间来处理并且根本没有执行。
  • 如果没有 isTimerActive() 函数,程序代码不会等待计时器完成,也不会有任何延迟。似乎代码在不等待异常的情况下运行。
  • 似乎 CAPL 处理循环非常糟糕。

我查看了 stackoverflow,以下论坛帖子讨论了我遇到的非常相似的问题,但没有提供任何可行的解决方案:

定时器的 CAPL 编程使用作为延迟

计时器是否正在运行,而循环是否处于活动状态?

除了 testwaitfortimeout() 之外,CAPL 中的延迟函数

4

2 回答 2

0

我发现您的代码存在很多问题。它实际上根本不像代码,而更像是伪代码。它可以在您的 CAPL 浏览器上编译吗?

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

如果这是一个函数声明,那么它缺少类型和返回值。另外,你预计什么时候main()被处决?

这同样适用于:

CANstart()

让我们退后一步。你需要延迟can传输的开始。如果您需要这样做,因为您有 CANalyzer/CANoe 之外的代码正在运行,那么我建议您通过命令行调用应用程序(请参阅指南以获取更多帮助)。

但是,如果您需要在设置配置中运行块,例如 Replay 块、Loggin 块或其他任何东西,我建议您执行以下操作:

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)
}

这能达到你的目标吗?请随时询问更多详细信息。

于 2018-04-18T07:41:05.350 回答
0

看来您的while (isTimerActive()==1) {陈述有问题。

CAPL 函数int isTimerActive需要参数timermstimer变量并返回值 1,如果计时器处于活动状态,否则0

您可以通过以下方式检查计时器是否处于活动状态以及经过的时间。

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

尝试将参数添加timerwhile (isTimerActive(Delay)==1) {

我不建议使用 while 语句,您可以直接使用计时器来调用该函数StartCANTransmitting(),您Main()应该是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();   
}
于 2019-12-05T10:03:41.853 回答