我正在尝试将一组CAN帧发送到CAN总线。我使用CAPL进行编程,使用CANalyzer8.5进行模拟,使用Panel designer创建按钮。我的要求是首先使用PANEL designer创建一个按钮。仅当按下按钮时,它才应开始向总线发送周期性CAN帧。对于如何实现它,我有点困惑。到目前为止,我已经成功地使用CAPL编写了两个独立的程序。第一个程序在启动时周期性地发送数据。第二个代码只在按钮被按下时发送一次数据。我想合并这两个代码,开始定期按下按钮发送。
第一个代码
/*@!Encoding:1252*/
includes
{
}
variables
{
msTimer mytimer;
message 0x100 A={dlc=8};
message 0x200 B={dlc=8};
message 0x300 C={dlc=8};
message 0x400 D={dlc=8};
}
on start
{
setTimer(mytimer,50);
}
on timer mytimer
{
A.byte(0)=0x64;
B.byte(4)=0x32;
C.byte(6)=0x20;
D.byte(7)=0x80;
output(A);
output(B);
output(C);
output(D);
setTimer(mytimer,50);
}第二个代码
/*@!Encoding:1252*/
includes
{
}
variables
{
message 0x100 A={dlc=8};
message 0x200 B={dlc=8};
message 0x300 C={dlc=8};
message 0x400 D={dlc=8};
}
on sysvar test::myButton
{
A.byte(0)=0x64;
B.byte(4)=0x32;
C.byte(6)=0x20;
D.byte(7)=0x80;
output(A);
output(B);
output(C);
output(D);
}如前所述,当我按下按钮时,它应该开始定期发送CAN帧。但问题是,我不能像下面这样在函数中调用函数:
on start
{
on sysvar test::myButton
{
....
}
}请给我一些建议。谢谢
发布于 2018-04-10 16:03:37
on start事件只在测量开始时调用一次,on sysvar也是一个事件,只是在您的示例中,当您按下某个按钮时它会被调用。
也许你可以试试这个:
variables
{
msTimer mytimer;
message 0x100 A={dlc=8};
message 0x200 B={dlc=8};
message 0x300 C={dlc=8};
message 0x400 D={dlc=8};
}
on start // This only gets called once at measurement start
{
A.byte(0)=0x64;
B.byte(4)=0x32;
C.byte(6)=0x20;
D.byte(7)=0x80;
}
on sysvar test::myButton // Starts the timer when button is pressed
{
setTimer(mytimer,50);
}
on timer mytimer
{
output(A);
output(B);
output(C);
output(D);
setTimer(mytimer,50);
}但是,在某些情况下,您可能希望使用函数cancelTimer再次停止计时器,可能需要使用不同的按钮或按下一个键。有关更多示例,请查看CANalyzer帮助中的CAPL部分。
发布于 2019-01-09 15:18:41
您的要求是-首先,将定期计时器设置为50ms。按下按钮。第二,输出关于计时器事件的消息(50ms周期)。所以你的代码应该是这样的-
variables
{
msTimer mytimer;
message 0x100 A={dlc=8};
message 0x200 B={dlc=8};
message 0x300 C={dlc=8};
message 0x400 D={dlc=8};
}
//This only gets called once at the measurement start because you want to send the same value in each period.
on start
{
A.byte(0)=0x64;
B.byte(4)=0x32;
C.byte(6)=0x20;
D.byte(7)=0x80;
}
on sysvar test::myButton // Starts the timer when button is pressed
{
setTimer(mytimer,50);
}
on timer mytimer
{
output(A);
output(B);
output(C);
output(D);
setTimer(mytimer,50);
}https://stackoverflow.com/questions/49729516
复制相似问题