ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

CANoe 杂谈

2026/8/6 17:50:47 拓冰建站 浏览量
CANoe 杂谈 这篇文章聊聊在工作中遇到的问题和分享一些好玩的函数不允许直接int 变量 变量可以写成int temptemp xvoid swap(int x, int y) {int temp x;x y;y temp;printf(在 swap 函数内x %d, y %d\n, x, y);}halt();暂停模拟断点variables { message InspectMessage gMsgInspect; message BreakPointMessage gMsgBreakPoint; message BreakPointMessage2 gMsgBreakPoint2; msTimer tSignalUpdateBreakPoint; byte gBreakPointMsgByte0 ; byte gBreakPointMsgByte1 ; byte gBreakPointMsgByte2 ; byte gBreakPointMsgByte3 ; byte gBreakPointMsgByte4 ; byte gBreakPointMsgByte5 ; byte gBreakPointMsgByte6 ; byte gBreakPointMsgByte7 ; byte gInspectMsgByte0 ; byte gInspectMsgByte1 ; byte gInspectMsgByte2 ; byte gInspectMsgByte3 ; byte gInspectMsgByte4 ; byte gInspectMsgByte5 ; byte gInspectMsgByte6 ; byte gInspectMsgByte7 ; } on message InspectMessage { gMsgInspect this; gInspectMsgByte0 gMsgInspect.SigInspect0; gInspectMsgByte1 gMsgInspect.SigInspect1; gInspectMsgByte2 gMsgInspect.SigInspect2; gInspectMsgByte3 gMsgInspect.SigInspect3; gInspectMsgByte4 gMsgInspect.SigInspect4; gInspectMsgByte5 gMsgInspect.SigInspect5; gInspectMsgByte6 gMsgInspect.SigInspect6; gInspectMsgByte7 gMsgInspect.SigInspect7; // Inspect() function will update // the variables in the debugger window if(sysvar::Inspect::InspectOnOff) { inspect(); } } on start { sysvar::Inspect::InspectOnOff 0; sysvar::BreakPoint::TimerBreakPoint 0; sysvar::BreakPoint::MessageBreakPointOnOff 0; sysvar::BreakPoint::SignalBreakPoint 0; setTimer(tSignalUpdateBreakPoint,2000); } on message BreakPointMessage { int CAPLError; int SigPointValue; SigPointValue this.SigBPoint0; if(sysvar::BreakPoint::SetError) { if(SigPointValue 0 sysvar::BreakPoint::SignalBreakPoint) { halt(); } CAPLError (1.0/this.SigBPoint0); // Diff through 0 } } on timer tSignalUpdateBreakPoint { if(sysvar::BreakPoint::TimerBreakPoint) { sysvar::BreakPoint::TimerBreakPoint 0; } setTimer(this,2000); } on message BreakPointMessage2 { gMsgBreakPoint2 this; // halt() function will halt the simulation, if the // message comes into the on message handler if(sysvar::BreakPoint::MessageBreakPointOnOff) { sysvar::BreakPoint::MessageBreakPointOnOff 0; halt(); } saveMessageBytes(); } void saveMessageBytes() { gBreakPointMsgByte0 gMsgBreakPoint2.SigBPoint0; gBreakPointMsgByte1 gMsgBreakPoint2.SigBPoint1; gBreakPointMsgByte2 gMsgBreakPoint2.SigBPoint2; gBreakPointMsgByte3 gMsgBreakPoint2.SigBPoint3; gBreakPointMsgByte4 gMsgBreakPoint2.SigBPoint4; gBreakPointMsgByte5 gMsgBreakPoint2.SigBPoint5; gBreakPointMsgByte6 gMsgBreakPoint2.SigBPoint6; gBreakPointMsgByte7 gMsgBreakPoint2.SigBPoint7; }stop():停止运行上位机若字符串太长我们可以通过用两个“”“”,把字符串分成两行来写// Phase 4: wait for 5min onoffsts should be 1 always if(testWaitForSignalOutsideRange(Msagonoffsts, 1, 1,5*1000*60)) { testStepFail(TRANS_TIMEOUT, onoffsts should be 1 always for 5min, but value: %d, $Msagonoffsts); return; }if (IsSimulated()) // dont activate tests when running in simulated mode { WriteLineEx(wrCAPLSink, wrError , This demo cannot run in simulated mode!); stop(); }linChangeSchedTable(dword tableIndex, dword slotIndex, dword onSlotIndex)实现调度表的调度切换的调度表切换的调度表的报文上一个调度表终止调度的报文on start { //linStopScheduler(); linChangeSchedTable(2,2); } on key a { linChangeSchedTable(2,2,4); }linRunSchedTableNTimes (1, 2, -2, -1);暂时只支持仿真模式真实节点不确定是否可用CAPL的函数里面定义的变量特性等同于C语言的静态变量报错1Start of measurement aborted:复制上位机后添加dbc出现此报错建议重新新建一个工程环境报错2真实节点与仿真节点冲突会会报错报错3capl保存的canner报错原因操作步骤不对1.先生成2.删除.can3.重启上位机不做任何操作强制转义符“%” - “%%”“” 和“”不能写在XML的引号内容内尖括号在XML中有定义Windows 路径中的反斜杠需用\\转义或直接使用正斜杠/CANoe 兼容。setLogFileName(Logging 2,\\log\\NIO_TG1_TC1_1_{MeasurementStart}.blf);变量类型打印使用方法Settimer获取信号值只有在获取到报文的时候才会激活所以定时器的起始位置很重要定时周期必须小于调度周期和报文间延时建议10msStmCreate_CSV函数testcase testcase_md(word mdtimeval) { byte i; //m1 // for(i 1;i8;i) // { // if(i 3) // { // $VehMd_l_LHZCU i; // testWaitForTimeout(mdtimeval); // $VehMd_l_LHZCU 0; // testWaitForTimeout(100); // } // // } dword stimId; //dbSignal StimSig; //Create stimulus for csv files and dbSignal stimId StmCreate_CSV(sysvar::A,UsgMd_l_LHZCU, stimulus.csv); writeEx(-3,1,st); //Start the process of reading the stimulus from csv file StmControl_Start(stimId); testWaitForTimeout(5000); //Destroy the created stimulus StmControl_Destroy(stimId); }第一行时间不能是0.00timer事件在test moudle的限制CAPL 的 on timer 事件处理函数运行在 Timer Handler 上下文中 这个上下文1. ❌ 不能发送诊断请求Diagnostic Request2. ❌ 不能执行 testWaitFor... 系列函数3. ❌ 不能直接调用某些测试库函数只能仿真调试进行局部变量 的查看