【问题标题】:Continuous message transmission in CANoeCANoe 中的连续消息传输
【发布时间】:2015-02-12 05:47:10
【问题描述】:

我使用 Vector 软件为 CANoe 中的测试自动化创建了一个测试环境,并且对于大多数测试用例,我需要传输连续的消息。

例如。 Msg1.Signal1 = 1 3 秒

Msg1.Signal1 = 4 2 秒。

我浏览了帮助内容和一些在线可用的 pdf,可以为此编写以下逻辑:

variables
{
message 0x555 msg1 ;
mstimer timer1; // define timer1
}
on message msg1
{
setTimer(timer1,3000); // initialize timer 
}
on timer timer1
{

setTimer(timer1,3000); // reset timer
msg1.signal1 = 1; // change the data
output(msg1); // output message
}

但是程序的整个运行时间大约是 200 毫秒,因此在 3 秒内没有传输 msg。用 2 秒的时间段重写了类似的代码。谁能告诉我代码有什么问题或如何进一步实现这一目标。

提前致谢。 问候, 维韦克

【问题讨论】:

  • on message msg1 ... 可以删除。我怀疑您以错误的方式使用环境。 (你必须点击那个红色按钮才能开始模拟)。
  • 尊敬的 user2225104,您说得对,点击红色按钮后模拟开始,但“on message msg1”是一个事件,每当 msg1 消息在总线上输出时,“on message msg1”事件就是执行。
  • 我认为on message msg1 表示如果 msg1 传入。但是如果你的 CAN 过滤器是打开的,你很可能会收到你发送的消息......
  • 您最好尝试使用交互式生成器块来查看您尝试执行的操作。
  • 要设置您的计时器,您可能需要在 start() 上添加一些内容。请参阅vector.com/portal/medien/vector_cantech/faq/… 并搜索“on start”。不知道是否还需要那种神秘的 @@ 东西。自从我上次使用那个东西以来已经有好几年了。 (第 36 页)

标签: automation embedded serial-communication capl


【解决方案1】:

这可以解决问题,在下面的示例中,您将使用两个独立的计时器,一个用于将信号设置为 4,另一个用于将其值更改为 1。

我添加了几个键盘事件,因此您可以轻松地开始和停止切换过程。

variables
{
    message 0x555 msg1 ;
    mstimer timer1; // Timer1 defined in ms    
    mstimer timer2; // Timer2 defined in ms
}
on key '1'
{
    // This event is called every time the key '1' is pressed
    // This will START the whole signal toggling procedure
    setTimer(timer1,3000);
}
on key '2'
{
    // This event is called every time the key '2' is pressed
    // This will STOP the whole signal toggling procedure
    cancelTimer(timer1);
    cancelTimer(timer2);
}

on timer timer1
{
    msg1.signal1 = 1;       // Set signal1 to 1 
    output(msg1);           // Send the message over CAN

    setTimer(timer2,3000);  // Let the signal1 be 1 by 3 seconds
}

on timer timer2
{
    msg1.signal1 = 4;       // Set signal1 to 4 
    output(msg1);           // Send the message over CAN

    setTimer(timer1,2000);  // Let the signal1 be 4 by 2 seconds
}

【讨论】:

  • 亲爱的 Jonas,我尝试在我的环境中运行相同的代码,但它不起作用。我需要对上述代码进行一些澄清: 1. 在 ontimer1 事件中,我们将 timer2 设置为 3 秒,这并不意味着 timer 2 将设置为 3 秒,而 timer1 设置为 2 秒。因为on timer的语法是:setTimer(msTimer t, long duration);礼貌:CAPL 帮助。我尝试自定义代码,但也没有用。
  • 嗨 Vivek,对 setTimer (myTimer,duration) 的调用意味着 myTimer 过期时间将设置为 duration ,换句话说,on timer myTimer 事件将在接下来的 duration 秒(或 msTimer 类型的毫秒)内被调用。上面示例背后的想法是在时间事件 timer1 和 timer2 之间不断切换。
  • 嗨 Jonas,感谢 cmets 关于计时器命令的问题,我有一个关于类似主题的问题,消息的并行传输:例如,如果我们想模拟 ex:如果msg1.signal1 = 1 持续 5 秒(CAN 消息)发送 msg2.signal2 = 4 持续 3 秒(LIN 消息)。我已经使用适当的检查点验证了我的代码,但无法在 CAnoe 的图形窗口中对其进行可视化,您知道为什么会发生这种情况吗?问候,维韦克
  • 嗨 Vivek,假设您有正确的通信,图形窗口设置正确,并且测量设置中没有特殊的过滤器,我认为在这样的窗口中可视化信号没有任何问题。我建议您首先在 Trace 窗口中检查数据传输。关于 LIN 消息,请记住这是一个主从协议,当您的模拟节点不是主节点时应特别小心。
  • 您好 Jonas,感谢您的知识转移,我不得不在 CAPL 浏览器中了解更多概念。通过对我的配置进行一些修改,该问题已得到解决,一位同事帮助了我。
猜你喜欢
  • 2017-02-22
  • 1970-01-01
  • 2023-04-06
  • 1970-01-01
  • 1970-01-01
  • 2018-06-15
  • 2018-10-23
  • 2020-12-16
  • 2017-05-30
相关资源
最近更新 更多