CAPL
CAPL
CAPL
C - A - P- L
CAN Access Programming Language (CAPL) => Preferred,
Communication Application Programming Language (CAPL)
CAPL - What & Why ????
“WHAT” is CAPL
This is definitely cheaper and faster way of testing the ECU than in a prototype car!
Residing/Working of CAPL
The CANalyzer or CANoe tool itself, without CAPL programs, is enough to execute
simple measurement and analysis.
With CAPL programs involved, measurement and analysis is greatly extended for
CAN communication. One area that the tool cannot perform without CAPL is
analysis that involves timing. CAPL can make analysis more efficient with the help
of Timers.
Relation between C, C++ & CAPL
Similarities of ‘C’
CAPL uses the same looping constructs and the Control structures used in C.
Supports standard C syntax.
CAPL extends the C foundation with extra network-specific functions and
data types.
Dissimilarities of ‘C’
All Local variables are static.
Allows Function Overloading.
Event Driven programming.
No Support for pointers and dynamic memory handling functions
(malloc/calloc).
No distinction between upper and lower case function names.
CAPL Browser Orientation
Can declare and initialize global variables.
Function invoking, event triggering and
processes execution are not allowed
CODE Compilation
Choosing Compile All compiles all of the CAPL programs that are currently open in the
CAPL Browser one at a Time.
A CAPL program is only found in one source file with the *.CAN extension that
requires no previously compiled functions from library files for compilation.
After the CAPL program is first compiled, a binary source file with the extension
*.CBF (CAPL Binary File) is created in the same directory as the *.CAN file.
Run-Time Errors
A number of CAPL run-time errors are monitored. Some of these run-time errors are
as follows:
Division by zero.
Exceeding the upper or lower limits of the array.
Exceeding the upper or lower limits of the offset in the data range of messages.
Stack overflow when CAPL subroutines are called.
Outputs a text message to the Write window. Write is based on the C function
printf..
Syntax: void write(char format[], ...);
Examples
float f=123.456;
on key 'h'
{
write("Hello World!");
write("f = %5.3f",f);
write("format is not supported for the given variable");
write(“%d”,f);
write(“%c”,f);
}
OUTPUT Function
OUTPUT
Outputs a message, or an error frame from the program block onto the CAN bus.
Syntax: output(message msg);
Example
Variable Declaration:
• message 0x7ED ABC;
Example:
on key F1
{
ABC.byte(0) = 0x01;
ABC.byte(1) = 0x02;
ABC.byte(2) = 0x03;
ABC.byte(3) = 0x04;
output(ABC);
}
EVENTS
An event is a specific occurrence, or a condition, that may invoke some necessary
action.
Events
pressing START or STOP
Keyboard entry
CAN message reception
Timer Timeout
Error frame events
CAN controller events
System (tool) events
user input via graphic panel (CANoe)
CAPL Interfaces
EVENTS (Continue..)
Events
4 Events
Prestart on preStart
Start on start
PreStop on preStop
Stop on stopMeasurement
On Pre-Start Event
On Prestart
Used for event handling before the start of CANalyzer/CANoe measurements.
Limitations
Can able to read data from files, initialize variables, or to print characters in the
Write window. Other actions, such as outputting a message onto the bus, are
not available in the on preStart event procedure.
Example
on preStart
{
// Set Start Delay to 10 seconds
setStartdelay(10000);
write("Node Activated after 10sec");
}
On Start Event
On Start
Example
On start {
setTimer(t1, 20);
msg1.byte(0)=0x20;
output(msg1);
}
On Prestop & On stopMeasurement Events
on preStop on preStop
{
message ShutdownReq m;
output(m);
DeferStop(1000); // measurement is stopped if ACK has not
// yet been received after one second
}
on message ShutdownAck
{
CompleteStop();
}
on stopMeasurement
4 Events
Example
On message : Reacts upon receiving of message
variables
{
message 0x555 ABC;
}
/*** /***
some event handling code some event handling code
***/ ***/
} }
Message Selectors
Ways of Accessing Message
Accessing Data of a Message
Keywords:
BYTE (8 bits)
WORD (16 bits)
LONG (32 bits)
DWORD (32 bits)
Messagename.BYTE(0) 0x6E
Messagename.WORD(0)0x16E
Messagename.LONG(4)0x23C9B57A
TIMER Event
SetTimer
Sets a timer for the specified time duration.
Syntax: setTimer(Timer t, long duration);
Timer Variable Declaration:
1. msTimer ABC;
2. Timer ABC;
Parameters : Variable of type Timer or msTimer and the duration of the timer in
units of seconds or milliseconds.
Example
Example
1st 2nd 3rd
on key ‘a’
{
cancelTimer(ABC);
}
TIMER Event (Continue…)
If you are trying to reset a timer, and that timer has not yet expired, you will
get a run-time warning in the Write window of CANalyzer/CANoe and your
attempt to reset that timer will be ignored. To reset a timer that is still
running, call the cancelTimer() function first and then set new timer with
setTimer() function.
Timetoelapse
Returns a value indicating how much more time will elapse before
an on timer event procedure is called
Istimeractive
Return value indicates whether a specific timer is active.
Example
on key ‘b’
{
Write(“pressed key ‘b’”);
}
Miscellaneous
Panel Creation
System Variables
EnvironMent Variables
File Operations
GateWay
Environment variables