本文主要是介绍CAPL创建与语法简介,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
CAPL 语言和C语言基本语法很相似,只是没有指针,list, set 等概念。
如何通过CANOE 创建自动测试节点
1. 创建一个CANoe configuration
2. 点击viewàSimulation Setup
3. 点击右键->insert xml test moudle
4. 右键点击新创建的XMLNode->Configuration
5. Test Script添加Test CaseXML
6. 点击TAB Components 进行创建或添加Test case files(.can)
7. 点击确认返回
8. 右键XML NODE->Edit *.can 进行编辑Test Casefile(.can)
整体结构
通过CAPL 语言编写的测试用例与方法需要以 .can 为扩展名的文件打开
属性页
Includes
同C语言中Includes 一样,可以包含其他.can文件,进而引用其他文件的内容
Variables
全局变量定义区域,主要分为以下几种类型
Integers
Ø byte
Ø word
Ø dword
Ø int
Ø long
Ø qword
Ø int64
Floating point numbers
Ø float
Ø double
Individual characters
Ø char
Map
float m[float];
m[4.1] = 5.5; //key is 4.1 (float) and value is 5.5 (float)
m[5.3] = 6.6;
write ("4.1 is mapped to %2.2lf",m[4.1]);
write ("5.3 is mapped to %2.2lf",m[5.3]);
for (float mykey : m)
{
write("%2.2lf is mapped to %2.2lf.", mykey, m[mykey]);
}
Enum
和C语言定义Enum 类型一致
Struct
和C语言定义结构体类型一致
注意:结构体属性只能是基本数据类型,不能是message类型,即使编译不存在问题
Message
Error Frame
System
与System相关的事件触发器
可以通过CANBrower 添加System事件触发器
CAN
与CAN相关的事件触发器
可以通过CANBrower 添加CAN 事件触发器
on message
The event procedure on message is called onthe receipt of a valid CAN message.
如何定义 message 事件触发
on message 123 | React to message 123 (dec, standard identifier), regardless of receiving chip |
on message 123x | React to message 123 (dec, extended identifier), regardless of receiving chip |
on message 0x123 | React to message 123 (hex, standard identifier), regardless of receiving chip |
on message 0x123x | React to message 123 (hex, extended identifier), regardless of receiving chip |
on message EngineData | React to message EngineData |
on message CAN1.123 | React to message 123 if it is received by CAN1 chip |
on message * | React to all messages |
on message CAN2.* | React to all messages received by CAN2 chip |
on message 0,1,10-20 | React to messages 0, 1 and 10 through 20 |
如何判断收到message 类型 |
on message * {
if (this.DIR == RX) {
write("This is RX message");
}
if (this.DIR == TX) {
write("This is TX message ");
}
}
on errorFrame
The event procedure on errorframe is calledwhen an error state (Error Frame) occurs on the bus.
如果通过errorcode进行区分
on errorFrame
{
switch (this.ecc & 0x20)
{
case (0x20): // in case of reception error
write ("%d Ch %dRxErr", this.time, this.can);
return;
case (0): // in case of transmission error
write ("%d Ch %dTxErr", this.time, this.can);
return;
};
}
on errorActive
CAN controller goes to ErrorActive.
重要属性,通过this 进行访问
errorCountRX (Receive error counter)
errorCountTX (Transmit error counter)
can (Assign the channel)
on errorPassive
CAN controller goes to ErrorPassive.
重要属性,通过this 进行访问
errorCountRX (Receive error counter)
errorCountTX (Transmit error counter)
can (Assign the channel)
on warningLimit
CAN controller reaches the Warning Limit.
重要属性,通过this 进行访问
errorCountRX (Receive error counter)
errorCountTX (Transmit error counter)
can (Assign the channel)
on busOff
CAN controller goes to Bus Off.
重要属性,通过this 进行访问
errorCountRX (Receive error counter)
errorCountTX (Transmit error counter)
can (Assign the channel)
Function
定义全局方法
格式: 返回类型 方法名(参数….)
Test Cases
定义全局测试用例
格式:testcase 名称
重要的系统API
Message Functions
Signal Functions
Test Functions
Wait Functions
String Functions
Time Functions
Trigonometric and Mathematical Functions
File Functions
Memory Functions
CANoe and CANDB Functions
这篇关于CAPL创建与语法简介的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!