name: capl-reference description: Comprehensive CAPL scripting reference for Vector CANoe CANalyzer. Use when user asks about CAPL syntax, event-driven programming, message or signal handling, timers, system variables, diagnostic CAPL, test module syntax, DLL integration, or common CAPL pitfalls. Trigger keywords include CAPL, CANoe script, on message, on timer, testcase, diagnostic CAPL, CAPL DLL, UDS test script, automotive security test script.
CAPL (Communication Access Programming Language) is the event-driven scripting language for Vector CANoe/CANalyzer. It follows C89/C90 syntax constraints — no C99 or C++ features. This skill provides corrected, production-ready reference material for automotive diagnostic security testing with CAPL + DLL two-layer architecture.
// comments in strict C89 (CAPL compiler accepts them, but avoid for portability)snprintf — use sprintf (ensure buffer is large enough)strncpy_s — use strncpy, manually null-terminate_atoi64 — use atol() or parse hex manually{} is NOT supported — assign element by elementTestWaitForTimeout, TestStep, etc./*@!Encoding:936*/
includes
{
#include "Common.can"
}
variables
{
msTimer tCycle;
message 0x123 msg_Test;
long gCounter;
byte gData[8];
}
on start
{
gCounter = 0;
setTimer(tCycle, 100);
}
on timer tCycle
{
gCounter++;
msg_Test.dlc = 8;
msg_Test.byte(0) = gCounter;
output(msg_Test);
setTimer(tCycle, 100);
}
on message 0x456
{
write("Rx 0x456 byte0=0x%02X", this.byte(0));
}
| Event | Trigger | Typical Use |
|---|---|---|
on preStart |
Before measurement | Pre-init |
on start |
Measurement starts | Init, start timers |
on stopMeasurement |
Measurement stops | Cleanup |
on message ID |
Specific CAN frame received | Response logic |
on message * |
Any CAN frame | Logging (use with caution) |
on timer tName |
Timer expires | Periodic tasks, timeouts |
on key 'c' |
Key press | Manual trigger |
on sysvar_update |
SysVar changes | Panel/automation trigger |
on signal SigName |
Signal value changes | Signal-based logic |
小蔥技能站7w4.net每天更新,海量AI技能等你發現。
variables
{
message 0x100 msg_Tx;
message EngineData msg_Engine; /* DB-backed message */
}
on start
{
msg_Tx.dlc = 8;
msg_Tx.byte(0) = 0x11;
output(msg_Tx);
}
/* Access DB signal */
on message EngineData
{
write("Speed=%f", this.EngineSpeed);
}
/* Write signal and send */
on key 's'
{
msg_Engine.EngineSpeed = 1000;
output(msg_Engine);
}
testcase TC_SecurityAccess()
{
TestCaseTitle("TC_SA_01", "Security Access Level 1");
TestStep("SendSeed", "Send 27 01 RequestSeed");
/* send request... */
if (TestWaitForMessage(0x708, 1000) == 1)
{
TestStepPass("CheckResp", "Response received");
}
else
{
TestStepFail("CheckResp", "Response timeout");
}
}
Correct function names:
| Wrong (lowercase) | Correct (PascalCase) |
|---|---|
testWaitForTimeout |
TestWaitForTimeout |
testStep |
TestStep |
testStepPass |
TestStepPass |
testStepFail |
TestStepFail |
testCaseTitle |
TestCaseTitle |
All take two parameters (name, description):
TestStep("StepName", "Description of what is being done");
TestStepPass("StepName", "Reason for pass");
TestStepFail("StepName", "Reason for failure");
CRITICAL: CAPL DLL functions are NOT discovered via the Windows DLL export table.
They are registered in a special CAPL_DLL_INFO4 table[] array that CANoe
reads at load time. This is completely different from standard __declspec(dllexport).
Path varies by version, search for CAPLdll under:
C:\Users\Public\Documents\Vector\CANoe <version>\Sample Configurations\Programming\CAPLdll
Open the .sln in Visual Studio. The sample project already has:
- Correct header dependencies
- CAPL_DLL_INFO4 table[] format for your CANoe version
- Calling convention macros (CAPL_DLL_CDECL, CAPL_FARCALL, etc.)
- onCaplInit() / onCaplExit() wiring
In capldll.cpp, add your function following the same pattern as existing functions:
long MyAdd(long a, long b)
{
return a + b;
}
Add an entry to the table (format varies by CANoe version — always copy from the existing entries in your sample project):
CAPL_DLL_INFO4 table[] =
{
/* existing entries — do NOT remove */
{
"MyAdd",
(CAPL_FARCALL)MyAdd,
"long",
"long a, long b",
CAPL_DLL_CDECL,
0,
CDLL_EXPORT
},
{ 0, 0 } /* END MARKER — must keep */
};
Field meanings:
1. "MyAdd" — function name visible to CAPL
2. (CAPL_FARCALL)MyAdd — function pointer
3. "long" — return type string (tells CAPL the return type)
4. "long a, long b" — parameter types string (tells CAPL the argument types)
5. CAPL_DLL_CDECL — calling convention (use the macro from the sample project)
6. 0 — reserved
7. CDLL_EXPORT — export flag
The { 0, 0 } entry MUST be the last entry — it is the table terminator.
| Setting | Value | Why |
|---|---|---|
| Platform | Win32 or x64 | MUST match CANoe bitness exactly |
| Config | Release (deploy) / Debug (dev) | |
| Runtime Library | /MD (recommended) | Avoid /MT — causes cross-boundary memory issues |
| Character Set | Multi-Byte or Unicode | Match your CAPL string encoding |
Note: The reference document mentions /MT (static CRT) as an option to avoid
needing VC++ redistributable on target machines. This works BUT beware:
- Memory allocated in DLL cannot be freed by CANoe, and vice versa
- For simple DLLs this is fine; for DLLs that pass dynamic memory, use /MD
Configuration → Programming → CAPL DLL (or Options → CAPL → DLL).dll fileon key 't'
{
long ret;
ret = MyAdd(10, 20);
write("MyAdd(10,20) = %d", ret);
}
| Type String | C/C++ Type | Direction | Notes |
|---|---|---|---|
"long" |
long |
in/out | Most common |
"double" |
double |
in/out | |
"char*" |
char* |
reference | String buffer |
"byte*" |
unsigned char* |
reference | Binary data |
"VALUE" |
value | in | By value (numbers) |
"REFERENCE" |
pointer | in/out | For arrays, strings, output buffers |
For arrays/buffers, always pass the length as a separate long parameter:
long ProcessData(unsigned char* data, long len)
{
if (data == 0 || len <= 0) return -1;
/* process data[0] to data[len-1] */
return 0;
}
See references/capl_pitfalls.md for the full list with explanations.
references/capl_pitfalls.md — Detailed pitfall explanations and correctionsreferences/capl_test_templates.md — Reusable test case templates for UDS/securityreferences/capl_dll_guide.md — DLL compilation and CAPL_DLL_INFO4 integration guidereferences/capl_pitfalls.md when user reports a CAPL errorreferences/capl_test_templates.md這個Skill質量不錯,專門解決CAPL指令碼開發中的常見問題和難點。它對C89語法限制、事件處理、DLL整合等做了清晰說明,特別是能幫助開發者避免像函式命名大小寫、變數宣告位置這樣的典型錯誤。不過內容專業性較強,更適合有經驗的開發者;涉及汽車診斷測試的內容較多,通用性一般;部分文件末尾還有截斷缺失。入門使用者可能會覺得內容偏深,中高階使用者會比較受益。