You are on page 1of 2

Tips and tricks for the

use of CAPL
CAPL is a programming language available in the software tools CANoe and
CANalyzer. In three consecutive articles, CAPL fundamentals will be discussed
as well as tips for all levels of user knowledge.

and these names can be


Authors
T his first part focuses on
the basics of CAPL. It is
primarily intended for those
original focus on CAN has
long been extended to all au-
tomotive bus systems such
used directly in the program
code. In Figure 1, they are the
who are new to this language; as LIN, Flexray, Most, J1587, names “EngineState” for a
however, it also offers a few as well as a few others like message and “EngineSpeed”
insights for well-informed us- Arinc and CANopen. for a signal in this message.
ers into the motivation be- As in many other lan- CAPL programs do
hind individual CAPL con- guages, the syntax of CAPL not give the user any point-
structs. The second part will is closely based on the syn- er types to use. Right from
discuss advanced function- tax of the C language. Those the outset this excludes nu-
Marc Lobmeyer alities of CAPL. Finally, the who are familiar with C, C#, merous potential program-
third part will address perfor- or various modern script lan- ming errors and causes of
mance and memory needs guages will quickly be quite program crashes, such as
and offers tips and tricks on comfortable using CAPL. those that frequently happen
using databases and asso- However, a few unique as- in C programming. Nonethe-
ciative arrays. pects distinguish a CAPL pro- less, since pointers − aside
For over 20 years – it gram from a C program: from their susceptibility to er-
was initially used in CANalyz- CAPL programs are rors − also represent a very
er for DOS – CAPL has been event-driven. This means powerful concept, CAPL pro-
used to implement a broad that they consist of individ- vides a substitute for some
Roman Marktl bandwidth of tasks: from ual functions, each of which things, e.g. associative ar-
simple stimuli to the simula- reacts to an event within the rays as a substitute for dy-
Vector Informatik GmbH tion of complex bus nodes. system under analysis: re- namic memory. 

Ingersheimer Str. 24 In the following, CANoe is il- ceipt of a message, change One important proper-
DE-70499 Stuttgart lustratively named for the two of a signal, expiration of a ty that CAPL shares with C
Tel.: +49-711-80670-400 products CANoe and CAN- timer, or even a change in the should be mentioned: CAPL
Fax: +49-711-80670-555 alyzer. The goal of CAPL has environment. To react to the is always compiled, i.e. it is
always been to solve specific message “EngineState”, for converted to efficiently exe-
Links tasks as simply as possible. example, you would use: “On cutable and flexible machine
www.vector.com Typical tasks are reacting to message EngineState” (Fig- code. 

received messages, check- ure 1).
ing and setting signal val- CAPL programs use Example: a simple
ues and sending messages. specific databases for the CAPL program
A program should restrict it- concepts of the system un-
self to precisely these things der analysis. Messages and In Figure 1 a simple CAPL
and not require any addition- signals get their names there, program is presented, which
al overhead.
Many programming
tasks that CANoe users typ- CAPL
ically perform might actually
be as brief and trivial as the CAPL is a procedural programming language
example presented below – similar to C, which was developed by Vector
of course many other tasks Informatik. The execution of program blocks
are not so trivial. That is why is controlled by events. CAPL programs are
CAPL has been continually developed and compiled in a dedicated browser.
extended over the years to This makes it possible to access all of the objects
be a tool that can also solve contained in the database (messages, signals,
complex tasks according to environment variables) as well as system variables.
the principle “as simple as In addition, CAPL provides many predefined
possible”. functions that support working with the CANoe and
“CAPL” is an acronym CANalyzer development, testing and simulation
for Communication Access tools.
Programming Language. The

42 CAN Newsletter 2/2014


Figure 1: A simple example of a CAPL program

performs one of the ba- signals it contains are condi- Lines 7 to 9 show a has been just transmit-
sic tasks of a bus monitor- tioned for display on a pan- minimal form of a message ted. Only received messag-
ing tool: it listens to traffic on el, and they are routed to the event procedure. This func- es should be considered in
the bus and prepares a cou- panel for graphic display. 
 tion is called whenever this this program (value RX), be-
ple of events on the bus for message has been transmit- cause a message sent by the
observation/monitoring by Description of ted on the bus. In reference node itself would also trig-
the user. This is a shortened, the program to CAN, this means that the ger an event procedure (val-
sample CANoe program: precise time point is the TX or ue TX). In this case, an error
“Display.can” from the sam- T

 he line numbers are not RX interrupt of the CAN con- message would be output in
ple “Easy.cfg”. In the follow- part of the CAPL program troller, i.e. immediately after line 15.
ing, first the overall function- and are only inserted here correct transmission of the Since conditioning of the
ality is briefly summarized, to make it easier to refer- message. The message that signal for display on the user
and then the individual sec- ence individual lines or sec- triggers the call of the partic- interface (a panel on which
tions are described in more tions. To achieve the most ular function is referenced by different states are shown by
detail. compact representation pos- “this” syntax. different bitmaps) is some-
sible, opening brackets were In line 8, the value of what more complex, its im-
Task description not placed on a separate the “EngineSpeed” signal is plementation is outsourced to
line. I
 n a CAPL program, it is read out from the received a separate function: In line 13,
The task is to observe a CAN possible to define global vari- message (“this”) and is as- “SetLightDsp” is called with
network whose elements ables and constants. This is signed to a system variable the two message signals
– e.g. bus nodes, messag- done in the “variables” sec- with a conversion (/1000.0). that are needed as param-
es and transported signals tion (lines 1 to 5). These Lines 11 to 17 show a mes- eters. Finally, lines 19 to
– are described in a data- constants and variables are sage event procedure for the 28 define a separate function,
base. When the “EngineS- globally defined for this pro- “LightState” message, which which writes different values
tate” message is received, gram: they can be used any- transmits the information for to the system variable “Light-
then the Engine-Speed sig- where in the program, but not a turn signal flasher. Its pro- Display” in the “Lights” name
nal it contains is conditioned in other programs within the cessing is similar to that of space according to the value
for display on a display pan- same CANoe application. the “EngineState” message of the transmitted signal. In
el, and it is routed to the pan- The other sections define re- with the following unique as- this demo configuration, this
el. When the “LightState” actions to events (lines 7 to pects: In line 12, the direc- variable then selects the ap-
message is received, the 17) and an auxiliary function tion flag (.dir) is now checked propriate bitmap on a display
“HeadLight” and “FlashLight” (lines 19 to 28). in the message (“this”) that panel.

44 CAN Newsletter 2/2014

You might also like