簡體   English   中英

使用 CAPL 發送消息/注入消息

[英]Send Message/ Inject a message with CAPL

我是 CANoe 的新手,也是 CAPL 語言的新手。 但是我想問你:如何在ECU的網絡上用CAPL發送消息。 例如:我想發送一個十六進制數(這是一個 ECU 的問題),然后我想看到這個問題的響應。

我不知道我是否很清楚,但是,如果您有任何答案,我將不勝感激。

在 CAPL 中發送消息

您可以在任何事件上發送一條消息(或多條消息),例如按鍵、接收到另一條消息、接收到錯誤幀或定時器到期。 發送事件消息涉及創建事件過程、聲明要發送的消息以及在事件過程中發送消息。 可以將消息聲明為全局變量,以便可以在任何事件過程中訪問它。 如消息對象部分所示,您可以在程序中聲明消息的結構,也可以使用關聯的數據庫。 在此示例中,我們將在“全局變量”窗口中聲明每個變量之一

variables 
{
  message EngineData msg1; // Defined in database
  message 0x101 msg2;      // Standard message 101 (hex)
  message 0x105x msg3;     // Extended message 105 (hex)
}

現在,要發送消息,我們只需要將其中一行放入事件過程中:

output(msg1); 
output(msg2);

當然,我們也可以在發送前給消息添加數據。 EngineData 消息具有在數據庫中定義的信號,但其他消息沒有。 因此,我們必須使用兩種不同的方法來向消息中添加數據。

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

回應訊息

on message 0x101   // This is the identifier of your response
{
  if(this.byte(0) == 0x16)
  {
    write("Response is the expected!");
  }
}

要么

on message msg2   // This is the identifier of your response
{
  if(this.byte(0) == 0x16)
  { 
    write("Response is the expected!");
  }
}

您可以使用如下所示,

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
}

希望我澄清了你的問題。 如果您需要更多說明,請告訴我。

Joe 展示了消息(在本例中為十六進制值)的發送方式。 如果要查看響應,則需要知道響應 ID(例如 0x62C)

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!");
}

我希望這回答了你的問題。

我還有另一個問題,例如上面的示例。 我想對通過“消息時”事件(收到消息時)起作用的CAPL進行編程,但是我不想將包含的字節與另一個值進行比較,我想將消息信息保存在環境或系統變量中。 這些變量如何定義? 以及如何保存收到的消息中的值?

謝謝!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM