gpt4 book ai didi

can-bus - CAPL 编程使用 Timer 作为延迟

转载 作者:行者123 更新时间:2023-12-02 12:26:22 26 4
gpt4 key购买 nike

我一直在编写一个 CAPL 脚本,它会在一定的延迟后在每个 channel (2 个)上发送消息。我想使用 SetTimer()mstimer::isRunning 函数生成以下延迟。我可以使用 setTimer 函数,但我不知道如何使用 mstimer::isRunning。代码如下所示:

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

}

最佳答案

使用 isTimerActive() 方法代替 mstimer::isrunning 。如果计时器正在运行,isTimerActive() 返回 1;如果计时器过期,则返回 0。所以你的代码将如下所示:

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

}
}

但我不建议这样做。您可以通过 onTimer 输出第二条消息,而不是在 on start 中循环

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

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

如果您想保持通用,即不限制为 2 个 channel ,您可以采用一个变量并在计时器中递增它。

关于can-bus - CAPL 编程使用 Timer 作为延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30474842/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com