使用CAPL和CANalyzer在按钮按下时发送定期CAN信号 [英] Sending Periodic CAN signals on button press using CAPL and CANalyzer

查看:1559
本文介绍了使用CAPL和CANalyzer在按钮按下时发送定期CAN信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一组CAN帧发送到CAN总线。我正在使用CAPL进行编程,并使用CANalyzer8.5进行模拟,并使用Panel Designer创建一个按钮。我的要求是首先使用PANEL Designer创建一个按钮。只有按下按钮,它才应开始向总线上定期发送CAN帧。我对如何实现它有些困惑。到目前为止,我已经设法使用CAPL编写了两个单独的程序。第一个程序在启动时定期发送数据。当按下按钮时,第二个代码仅发送一次数据。我想合并这两个代码,以在按下按钮时开始定期发送。

I am trying to send a set of CAN frames on to CAN bus. I am using CAPL to program and CANalyzer8.5 to simulate and Panel designer to create a button. My requirement is to first create a button using PANEL designer. Only on button press it should start sending periodic CAN frames on to the bus. I am a bit confused as to how to achieve it. So far I have managed to write two separate programs using CAPL. First program sends data at start periodically. Second code sends data only once when the button is pressed. I want to merge both the codes to start sending periodically on button press.

第一个代码

/*@!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定期帧。
但问题是,我无法在函数内调用以下函数:

So as mentioned, when i press the button, it should start sending the CAN frames periodically. But the problem is,i cannot call a function within function as below:

on start
{
    on sysvar test::myButton
    {
        ....
    }
}

请给我建议。谢谢

推荐答案

启动事件仅在测量开始时调用一次,启动sysvar 也是一个事件,只是当您按下某个按钮时,它才被调用。

The on start event is only called once at measurement start, on sysvar is also an event, just that in your case it gets called when you press a certain button.

也许尝试一下:

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部分。

However at some point you probably want to stop the timer again using the function cancelTimer maybe with the use of a different button or a press of a key. For more examples, take a look at the CAPL Section in the CANalyzer Help.

这篇关于使用CAPL和CANalyzer在按钮按下时发送定期CAN信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆