首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用CAPL发送消息/插入消息

使用CAPL发送消息/插入消息
EN

Stack Overflow用户
提问于 2017-07-28 17:04:04
回答 3查看 37.8K关注 0票数 3

我是CANoe新手,也是CAPL语言新手。但是我想问你:我如何在ECU的网络上发送带有CAPL的消息。例如:我想发送一个十六进制数(这是一个针对ECU的问题),然后我想看看这个问题的响应。

我不知道我是否说得很清楚,但如果你有任何答案,我将不胜感激。

EN

回答 3

Stack Overflow用户

发布于 2017-10-16 13:08:40

在CAPL中发送消息的

您可以在任何事件上发送一条消息(或多条消息),例如,按键、接收另一条消息、接收错误帧或计时器超时。发送事件消息涉及创建事件过程、声明要发送的消息以及在事件过程中发送消息。可以将消息声明为全局变量,以便可以在任何事件过程中访问它。如消息对象部分所示,您可以在程序中声明消息的结构,也可以使用关联的数据库。在本例中,我们将在[全局变量]窗口中分别声明一个

代码语言:javascript
复制
variables 
{
  message EngineData msg1; // Defined in database
  message 0x101 msg2;      // Standard message 101 (hex)
  message 0x105x msg3;     // Extended message 105 (hex)
}

现在,要发送一条消息,我们只需要将其中一行放入事件过程中:

代码语言:javascript
复制
output(msg1); 
output(msg2);

当然,我们也可以在发送消息之前向消息中添加数据。EngineData消息具有在数据库中定义的信号,但其他消息没有。因此,我们必须使用两种不同的方法向消息中添加数据。

代码语言:javascript
复制
msg1.EngSpeed.phys = 1000;
msg1.EngTemp.phys = 150;
msg1.IdleRunning = 1;
output(msg1);

msg2.DLC = 4;        // Allocate 4 data bytes in msg2
msg2.byte(0) = 0x16; // First word is 16 hex
msg2.byte(1) = 7;    // Second word is 7 decimal
output(msg2);

响应消息

代码语言:javascript
复制
on message 0x101   // This is the identifier of your response
{
  if(this.byte(0) == 0x16)
  {
    write("Response is the expected!");
  }
}

代码语言:javascript
复制
on message msg2   // This is the identifier of your response
{
  if(this.byte(0) == 0x16)
  { 
    write("Response is the expected!");
  }
}
票数 6
EN

Stack Overflow用户

发布于 2017-08-01 23:18:55

您可以按照下面的方式使用,

代码语言:javascript
复制
variables
{
    message BCMmsg01 msg_BCMmsg01; // declaration of message into a variable
}

on key 'z'
{
  msg_BCMmsg01.C_AutoLockCmd = 3; // assign the value to the message
  output(msg_BCMmsg01); //send the message to the CAN bus
}

希望我已经澄清了你的问题。如果你需要更多的澄清,请告诉我。

票数 5
EN

Stack Overflow用户

发布于 2017-09-01 00:14:59

Joe展示了消息(在本例中是十六进制值)的发送方式。如果您想查看响应,则需要知道响应ID (例如0x62C)

代码语言:javascript
复制
on message 0x62C    /* This is the identifier of your response */
{
   if(this.byte(X) == 0xYY) { /* X is the byte of the response you are interested and Y the value of that byte*/
   write("Response is the expected!");
}

我希望这能回答你的问题。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45369254

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档