Transcription of Quick Introduction To CAPL - CAN in Automation
1 Quick Introduction To CAPL Version 02/09/03 Application Note AN-AND-1-113 Author(s) Bruce Emaus Restrictions Public Document Abstract This application note is a brief Introduction to CAPL, the easy-to-use C-based programming language and integrated programming environment inside both CANalyzer and CANoe. The focus is to help the beginning CAPL programmer. Table of Contents Copyright 2003 - Vector CANtech, Inc. 1 Contact Information: or 1-248-449-9290 CAPL Programming .. 1 CAPL 1 Node Emulation .. 1 Network 1 Node Testing .. 2 2 Bus Separator .. 2 CAPL Programming Environment .. 2 CAPL Responds to 3 Example CAPL Programs .. 4 Event Message Transmission.
2 4 Periodic Message Transmission .. 5 Conditionally Periodic Message Transmission .. 7 Limitations of 8 Conclusions .. 8 Contacts .. 9 CAPL Programming For CAN-based networks, modules, and distributed embedded systems, Communication Application Programming Language, CAPL, makes it possible to program the CANalyzer for developer-specific applications that use the CAN protocol. CAPL may also be used in the CANoe tool for distributed product development, CAPL Applications Node Emulation Using the programmable version of CANalyzer, one can emulate functions of a node including the transmission of event, periodic, and conditionally periodic messages. Users can create conversational responding messages to the reception of designated messages.
3 Network Emulation Using CAPL, CANalyzer can emulate the system-level data traffic of all remaining nodes. Quick Introduction To CAPL Application Note AN-AND-1-113 2 Node Testing During a portion of CAN-based module development, CANalyzer can be used to test the module s communication behavior. Evaluation of message timing, handling of Bus Off, and other functions are easy to accomplish. Gateway The programmable CANalyzer can be used as a temporary or permanent gateway (or bridge) between different CAN buses to exchange data. Bus Separator Another target application is to insert CANalyzer Pro between a node to be tested and the actual network. Such configurations can be used during system-level development to isolate (and optionally modify) behavior.
4 The ability to interconnect modules at different revision levels to the distributed product in order to continue development is also another possible application. CAPL Programming Environment Even though CAPL can be thought of as a procedural programming language, CAPL can also be considered as a programming environment. Within this programming environment a user can create, modify, and maintain CAPL programs that can interface with a wide variety of inputs, outputs and other functions. Start-stop events, keyboard entry events, the ability to transmit and receive CAN messages, interaction with the serial port and parallel port, the use of timers, and the ability to interconnect to customer specific DLLs are some of the interface choices available inside the CAPL programming environment.
5 Most programs are developed using the CAPL Browser, which provides an easy to use "edit-thru-compilation" development process. Even though provided as an integrated component of CANalyzer or CANoe, the CAPL Browser application program can also be used separately. Quick Introduction To CAPL Application Note AN-AND-1-113 3 CAPL Responds to Events In general, CAPL programs are simply designed to detect events and then execute the associated event procedure. For example, you could output the text "Start Test" to the Write window upon clicking on the start button of CANalyzer by using the following program. on start{write("Start Test");} The types of events that can be detected in CAPL include - the pressing of the start stop button user keyboard entry CAN message reception the timeout of a timer user input via a graphic panel (available only in CANoe).
6 Based on this "event causes procedural activity" technique, CAPL programs are constructed and organized as a collection of event procedures. The CAPL Browser is conveniently structured into different groupings of event procedures. These so-called event procedural groups or event classes include system, CAN controller, CAN message, timer, keyboard, and CAN error frame as shown in the CAPL event table. Quick Introduction To CAPL Application Note AN-AND-1-113 4 Example CAPL Programs Let's take a look at how much CAPL code is necessary to develop the three common information transfer methods (or transfer dialogs) used by most CAN-based distributed embedded systems. Our three examples will include the transmission of an event message, the transmission of a periodic message, and the transmission of a conditionally periodic message.
7 Event Message Transmission When information only needs to be transferred on an event basis, the event message is used. This sample program uses the pressing of the 'b' key on the PC keyboard to initiate a single CAN message transmission. Quick Introduction To CAPL Application Note AN-AND-1-113 5 It is important to note that the use of each message must include a definition within the global variables. In this example we have defined the message msg1 as having a CAN identifier of 555 hex and data length code (dlc) or data size of one byte. Note - While this example shows defining a message completely within this CAPL program, it is easy to use the CANdb program (another related application program in the Vector CAN tool suite) to link a user-defined, industry defined or corporate specific messaging database.
8 In the "keyboard" event class we insert (via the right mouse button) a new procedure for the 'b' key press. Don't forget to include the single quote marks. In this on key procedure, we fix the first byte of the can message data equal to hexadecimal AA and then use the internal CAPL function output to transmit the message. Notice that the message name used in the output function is identical to the name defined in the global variables. variables{message 0x555 msg1 = {dlc=1};}on key 'b'{ (0)=0xAA;output(msg1);} Periodic Message Transmission When information requires transferring on a repetitive basis, the periodic message is used. Quick Introduction To CAPL Application Note AN-AND-1-113 6 To send the periodic message requires the use of a timer and this timer must be defined by name in the global variables area.
9 To get this timer running, we have chosen to initialize the timer in the "on start" event procedure that is executed upon clicking on the tool start button. We need to use one of the intrinsic CAPL functions called setTimer to initialize the time value to 100 milliseconds. When this timer expires (or times out), the corresponding "on timer" event procedure will be executed. Within this "on timer" event procedure the timer will be reset again to 100 milliseconds. Additionally, we increment the first message data byte before sending the CAN message using the CAPL output function. This repetitive process will continue until one clicks on the tool's stop button. variables{message 0x555 msg1 = {dlc=1};mstimer timer1; // define timer1}on start{setTimer(timer1,100); // initialize timer to 100 msec}on timer timer1{setTimer(timer1,100); // reset (0)= (0)+1; // change the dataoutput(msg1); // output message}With respect to the CAPL program development, for this periodic message example, CAPL code must be entered into three different locations and a total of 6 lines of code are used.
10 Quick Introduction To CAPL Application Note AN-AND-1-113 7 Conditionally Periodic Message Transmission When information requires transferring on a repetitive basis only when a certain set of conditions is true, the conditionally periodic message is used. This CAPL program uses the pressing of the 'a' key on the PC keyboard to toggle between no message transmission and a periodic message transmission. To send a conditionally periodic message also requires the use of a timer, but this timer does not need to run continuously. We have chosen to activate or deactivate the timer based upon the pressing of the <a> key sequence. The first press of the <a> key will start the periodic message and the second press of the <a> key will stop the periodic message.