
Sample program
Write A sample CAPL script
variables
{
message 0x779 senda;
message 0x778 sendc;
}
on message 0x779
{
write("message received");
sendc.dlc=8;
if ( this.byte(0) == 0x02)
{
sendc.byte(0)=0x02;
sendc.byte(1)=0x50;
if ( this.byte(2) == 0x01)
sendc.byte(2)=0x01;
else if ( this.byte(2) == 0x02)
sendc.byte(2)=0x02;
else
if ( this.byte(2) == 0x03)
sendc.byte(2)=0x03;
sendc.byte(3)=0x00;
sendc.byte(4)=0x00;
sendc.byte(5)=0x00;
sendc.byte(6)=0x00;
sendc.byte(7)=0x00;
output(sendc);
write ( " message sent postive respone)");
}
else {
sendc.byte(0)=0x03;
sendc.byte(1)=0x7f;
sendc.byte(2)=0x10;
sendc.byte(3)=0x13;
sendc.byte(4)=0x00;
sendc.byte(5)=0x00;
sendc.byte(6)=0x00;
sendc.byte(7)=0x00;
output(sendc);
}
}
on start
{
write(" Press a for start start diagnootic default session");
write("Press b for start start diagnootic programming session");
write("Press c for start start diagnootic extended session");
write("hi");
write("hi");
write("hi");
write("hi my first message");
}
on key 'a'
{
write (" this is key Start Diagnotic ");
senda.dlc=8;
senda.byte(0)=0x02;
senda.byte(1)=0x10;
senda.byte(2)=0x01;
senda.byte(3)=0x00;
senda.byte(4)=0x00;
senda.byte(5)=0x00;
senda.byte(6)=0x00;
senda.byte(7)=0x00;
output(senda);
write ( " message sent)");
}
on key 'b'
{
write (" this is key Start Diagnotic ");
senda.dlc=8;
senda.byte(0)=0x02;
senda.byte(1)=0x10;
senda.byte(2)=0x02;
senda.byte(3)=0x00;
senda.byte(4)=0x00;
senda.byte(5)=0x00;
senda.byte(6)=0x00;
senda.byte(7)=0x00;
output(senda);
write ( " message sent)");
}
on key 'c'
{
write (" this is key Start Diagnotic ");
senda.dlc=8;
senda.byte(0)=0x02;
senda.byte(1)=0x10;
senda.byte(2)=0x03;
senda.byte(3)=0x00;
senda.byte(4)=0x00;
senda.byte(5)=0x00;
senda.byte(6)=0x00;
senda.byte(7)=0x00;
output(senda);
write ( " message sent)");
}
on key 'z'
{
write (" this is key c");
senda.dlc=8;
senda.byte(0)=0xcc;
senda.byte(1)=0x11;
senda.byte(2)=0x22;
senda.byte(3)=0x33;
senda.byte(4)=0x44;
senda.byte(5)=0x55;
senda.byte(6)=0x66;
senda.byte(7)=0x77;
output(senda);
write ( " message sent)");
}
2. Write a CAPL Script to start sending tester present request every S3 time on the press of Key ‘a’ can be done using timer function in CAPL?
/*@!Encoding:65001*/
variables
{
message 0x779 senda;
message 0x778 sendc;
msTimer tmr_TestPresent; // Timer variable for sending Tester Present
}
on start
{
write(" Press a for tester present");
write("hi");
write("hi");
write("hi my first message");
}
on key 'a'
{
setTimer(tmr_TestPresent, 3000); // Start the timer when 'a' key is pressed (S3 = 3000 milliseconds)
write (" this is key Start tester present ");
senda.dlc=8;
senda.byte(0)=0x02;
senda.byte(1)=0x3E;
senda.byte(2)=0x01;
senda.byte(3)=0x00;
senda.byte(4)=0x00;
senda.byte(5)=0x00;
senda.byte(6)=0x00;
senda.byte(7)=0x00;
output(senda);
write ( " message sent)");
}
on key 'z'
{
write (" this is key c");
senda.dlc=8;
senda.byte(0)=0xcc;
senda.byte(1)=0x11;
senda.byte(2)=0x22;
senda.byte(3)=0x33;
senda.byte(4)=0x44;
senda.byte(5)=0x55;
senda.byte(6)=0x66;
senda.byte(7)=0x77;
output(senda);
write ( " message sent)");
}
on message 0x779
{
write("message received");
sendc.dlc=8;
if ( this.byte(0) == 0x02)
{
sendc.byte(0)=0x02;
sendc.byte(1)=0x7E;
if ( this.byte(2) == 0x01)
sendc.byte(2)=0x01;
sendc.byte(3)=0x00;
sendc.byte(4)=0x00;
sendc.byte(5)=0x00;
sendc.byte(6)=0x00;
sendc.byte(7)=0x00;
output(sendc);
write ( " message sent postive respone)");
}
else {
sendc.byte(0)=0x03;
sendc.byte(1)=0x7f;
sendc.byte(2)=0x3E;
sendc.byte(3)=0x13;
sendc.byte(4)=0x00;
sendc.byte(5)=0x00;
sendc.byte(6)=0x00;
sendc.byte(7)=0x00;
output(sendc);
}
}
on timer tmr_TestPresent
{
write("Sending Tester Present request\n"); // Placeholder for sending Tester Present request
// Add your code here to send the Tester Present request using appropriate CAN message functions
// For example:
// canSend(message); // Replace 'message' with your Tester Present message
setTimer(tmr_TestPresent, 3000); // Restart the timer for periodic execution
}
3. Write a program to send a message (ID 0xAA) for 5 times with periodicity of 100ms. After that transmit on another message (ID 0xBB) for 5 times with periodicity of 200ms. Do this using single timer?
/*@!Encoding:65001*/
variables
{
int counter1 = 0; // Counter to track the number of transmissions
int counter2 = 0; // Counter to track the number of transmissions
message 0xAA senda;
message 0xBB sendb;
msTimer tmr; // Timer variable for periodic transmission
}
on start
{
write("hi");
write("hi");
write("hi my first message");
}
on key 'a'
{
setTimer(tmr, 100); // Start the timer when 'a' key is pressed
write ( " message sent)");
}
on timer tmr
{
if (counter1 < 5) {
setTimer(tmr, 100); // Change the timer interval to 100ms after transmitting 0xAA 5 times
write (" this is key sending AA ");
senda.dlc=8;
senda.byte(0)=0x08;
senda.byte(1)=0xAA;
senda.byte(2)=0xAA;
senda.byte(3)=0xAA;
senda.byte(4)=0xAA;
senda.byte(5)=0xAA;
senda.byte(6)=0xAA;
senda.byte(7)=0xAA;
output(senda);
}
counter1++;
if(counter1 > 5){
if (counter2 < 5) {
setTimer(tmr, 200); // Change the timer interval to 200ms after transmitting 0xBB 5 times
write (" this is key sending BB ");
sendb.dlc=8;
sendb.byte(0)=0x08;
sendb.byte(1)=0xBB;
sendb.byte(2)=0xBB;
sendb.byte(3)=0xBB;
sendb.byte(4)=0xBB;
sendb.byte(5)=0xBB;
sendb.byte(6)=0xBB;
sendb.byte(7)=0xBB;
output(sendb);
}
counter2++;
}
}
4. Explain how you are setting “Loss of Communication” DTC on Canoe tools?
/*@!Encoding:65001*/
variables
{
message 0x779 senda;
message 0x778 sendb;
msTimer tmr; // Timer variable for periodic transmission
int communicationlost = 0;
int counter1 = 0; // Counter to track the number of transmissions
}
on start
{
write("hi");
write("hi");
write("hi my first message");
}
on key 'a'
{
setTimer(tmr, 5000); // Start the timer when 'a' key is pressed
write ( " message not sent)");
}
on key 'z'
{
write (" this is key c");
senda.dlc=8;
senda.byte(0)=0xcc;
senda.byte(1)=0x11;
senda.byte(2)=0x22;
senda.byte(3)=0x33;
senda.byte(4)=0x44;
senda.byte(5)=0x55;
senda.byte(6)=0x66;
senda.byte(7)=0x77;
output(senda);
write ( " message sent)");
}
on message 0x779
{
write("message received");
sendb.dlc=8;
if ( this.byte(0) == 0x03)
{
write (" this one DTC confirmed ");
sendb.dlc=8;
sendb.byte(0)=0x05;
sendb.byte(1)=0x59;
sendb.byte(2)=0x01;
sendb.byte(3)=0xFF;
sendb.byte(4)=0x01;
sendb.byte(5)=0x01;
sendb.byte(6)=0x00;
sendb.byte(7)=0x00;
output(sendb);
write ( " message sent postive respone)");
}
else if ( this.byte(0) == 0x02)
{
write (" this is reading the communication lost C11500 DTC ");
sendb.dlc=8;
sendb.byte(0)=0x07;
sendb.byte(1)=0x59;
sendb.byte(2)=0x02;
sendb.byte(3)=0x08;
sendb.byte(4)=0xC1;
sendb.byte(5)=0x15;
sendb.byte(6)=0x00;
sendb.byte(7)=0x00;
output(sendb);
}else{
sendb.byte(0)=0x03;
sendb.byte(1)=0x7f;
sendb.byte(2)=0x10;
sendb.byte(3)=0x13;
sendb.byte(4)=0x00;
sendb.byte(5)=0x00;
sendb.byte(6)=0x00;
sendb.byte(7)=0x00;
output(sendb);
}
}
on timer tmr
{
write (" simulating loss of communication ");
/*message not sent
communicationlost = 0;
*/
communicationlost = 1;
if(communicationlost == 1)
{
if (counter1 < 1) {
setTimer(tmr, 5000);
write (" this is sending request for number of DTC with communication lost dtc confirmed");
senda.dlc=8;
senda.byte(0)=0x03;
senda.byte(1)=0x19;
senda.byte(2)=0x01;
senda.byte(3)=0x08;
senda.byte(4)=0x00;
senda.byte(5)=0x00;
senda.byte(6)=0x00;
senda.byte(7)=0x00;
output(senda);
setTimer(tmr, 5000); // Change the timer interval to 200ms after transmitting 0xAA 5 times
write (" this is request sending Read DTC with communication lost ");
senda.dlc=8;
senda.byte(0)=0x02;
senda.byte(1)=0x19;
senda.byte(2)=0x02;
senda.byte(3)=0x08;
senda.byte(4)=0x00;
senda.byte(5)=0x00;
senda.byte(6)=0x00;
senda.byte(7)=0x00;
output(senda);
// Set DTC with ID 0x1001 and sub ID 0x01 (Loss of Communication)
}
counter1++;
}
}
5. Send a message using IG block and print the first byte of the message on the write window using CAPL Script?
/*@!Encoding:65001*/
variables
{
message 0xAA senda;
msTimer tmr; // Timer variable for periodic transmission
int counter1=0;
}
on start
{
write("hi");
write("hi");
write("hi my first message");
}
on key 'a'
{
setTimer(tmr, 100); // Start the timer when 'a' key is pressed
write ( " message sent)");
}
on timer tmr
{
if (counter1 < 5) {
setTimer(tmr, 100); // Change the timer interval to 100ms after transmitting 0xAA 5 times
senda.dlc=8;
senda.byte(0)=0x08;
senda.byte(1)=0xAA;
senda.byte(2)=0xBB;
senda.byte(3)=0xCC;
senda.byte(4)=0xDD;
senda.byte(5)=0xEE;
senda.byte(6)=0xFF;
senda.byte(7)=0x11;
output(senda);
write (" Frist byte is %X\n",senda.byte(0));
}
counter1++;
}
6. Send a message on using IG block with message ID 0xAA and print the message ID in write window using the “ on message “ event ( Hint use ‘this’ keyword )?
/*@!Encoding:65001*/
variables
{
message 0xAA senda;
msTimer tmr; // Timer variable for periodic transmission
int counter1=0;
}
on start
{
write("hi");
write("hi");
write("hi my first message");
}
on key 'a'
{
setTimer(tmr, 100); // Start the timer when 'a' key is pressed
write ( " message sent)");
}
on message 0xAA
{
write("message received with id %X",this.id);
}
on timer tmr
{
if (counter1 < 5) {
setTimer(tmr, 100); // Change the timer interval to 100ms after transmitting 0xAA 5 times
senda.dlc=8;
senda.byte(0)=0x08;
senda.byte(1)=0xAA;
senda.byte(2)=0xBB;
senda.byte(3)=0xCC;
senda.byte(4)=0xDD;
senda.byte(5)=0xEE;
senda.byte(6)=0xFF;
senda.byte(7)=0x11;
output(senda);
}
counter1++;
}
7. Using CAPL Send flow control frame on the trace window when first frame is send by IG block.
From IG: 0x779 10 10 2E 81 91 1 2 3
From CAPL : 0x778 30 00 00
/*@!Encoding:65001*/
variables
{
message 0x778 senda;
message 0x779 sendb;
}
on start
{
write("hi");
write("hi");
write("hi my first message");
}
on message 0x779
{
write("message received with id %X",senda.id);
senda.dlc=8;
if ( this.byte(0) == 0x10)
{
senda.byte(0)=0x30;
senda.byte(1)=0x00;
senda.byte(2)=0x00;
senda.byte(3)=0x00;
senda.byte(4)=0x00;
senda.byte(5)=0x00;
senda.byte(6)=0x00;
senda.byte(7)=0x00;
output(senda);
}
if ( this.byte(0) == 0x10)
{
sendb.dlc=8;
sendb.byte(0)=0x21;
sendb.byte(1)=0x05;
sendb.byte(2)=0x06;
sendb.byte(3)=0x07;
sendb.byte(4)=0x08;
sendb.byte(5)=0x09;
sendb.byte(6)=0x0A;
sendb.byte(7)=0x0B;
output(sendb);
}
if ( this.byte(0) == 0x21)
{
senda.dlc=8;
senda.byte(0)=0x30;
senda.byte(1)=0x00;
senda.byte(2)=0x00;
senda.byte(3)=0x00;
senda.byte(4)=0x00;
senda.byte(5)=0x00;
senda.byte(6)=0x00;
senda.byte(7)=0x00;
output(senda);
}
if ( this.byte(0) == 0x21)
{
sendb.dlc=8;
sendb.byte(0)=0x22;
sendb.byte(1)=0x0C;
sendb.byte(2)=0x0D;
sendb.byte(3)=0x00;
sendb.byte(4)=0x00;
sendb.byte(5)=0x00;
sendb.byte(6)=0x00;
sendb.byte(7)=0x00;
output(sendb);
}
if ( this.byte(0) == 0x22)
{
write("Positive response");
senda.dlc=8;
senda.byte(0)=0x03;
senda.byte(1)=0x6E;
senda.byte(2)=0x81;
senda.byte(3)=0x91;
senda.byte(4)=0x00;
senda.byte(5)=0x00;
senda.byte(6)=0x00;
senda.byte(7)=0x00;
output(senda);
}
}
8. Send message ID 0xAA for 5 times with periodicity of 100 msec, next 5 times with periodicity of 200 msec and next 5 times with 300 msec. use only one timer in CAPL?
/*@!Encoding:65001*/
variables
{
int counter1 = 0; // Counter to track the number of transmissions
int counter2 = 0; // Counter to track the number of transmissions
int counter3 = 0; // Counter to track the number of transmissions
message 0xAA senda;
msTimer tmr; // Timer variable for periodic transmission
}
on start
{
write("hi");
write("hi");
write("hi my first message");
}
on key 'a'
{
setTimer(tmr, 100); // Start the timer when 'a' key is pressed
write ( " message sent)");
}
on timer tmr
{
if (counter1 < 5) {
setTimer(tmr, 100); // Change the timer interval to 100ms after transmitting 0xAA 5 times
write (" this is key sending AA with 100");
senda.dlc=8;
senda.byte(0)=0x08;
senda.byte(1)=0xAA;
senda.byte(2)=0xAA;
senda.byte(3)=0xAA;
senda.byte(4)=0xAA;
senda.byte(5)=0xAA;
senda.byte(6)=0xAA;
senda.byte(7)=0xAA;
output(senda);
}
counter1++;
if(counter1 > 5){
if (counter2 < 5) {
setTimer(tmr, 200); // Change the timer interval to 200ms after transmitting 0xBB 5 times
write (" this is key sending BB with 200ms ");
senda.dlc=8;
senda.byte(0)=0x08;
senda.byte(1)=0xBB;
senda.byte(2)=0xBB;
senda.byte(3)=0xBB;
senda.byte(4)=0xBB;
senda.byte(5)=0xBB;
senda.byte(6)=0xBB;
senda.byte(7)=0xBB;
output(senda);
}
counter2++;
}
if(counter2 > 5){
if (counter3 < 5) {
setTimer(tmr, 300); // Change the timer interval to 200ms after transmitting 0xBB 5 times
write (" this is key sending CC with 300ms");
senda.dlc=8;
senda.byte(0)=0x08;
senda.byte(1)=0xCC;
senda.byte(2)=0xCC;
senda.byte(3)=0xCC;
senda.byte(4)=0xCC;
senda.byte(5)=0xCC;
senda.byte(6)=0xCC;
senda.byte(7)=0xCC;
output(senda);
}
counter3++;
}
}
9.Send message ID 0x123 for 5 times with periodicity of 100 msec send 00 in byte 0 and increment it by 5
/*@!Encoding:65001*/
variables
{
int counter1 = 0; // Counter to track the number of transmissions
message 0x123 senda;
msTimer tmr; // Timer variable for periodic transmission
}
on start
{
write("hi");
write("hi");
senda.byte(0)=0x00;
write("hi my first message");
}
on key 'a'
{
setTimer(tmr, 100); // Start the timer when 'a' key is pressed
counter1 = 0;
write ( " message sent)");
}
on timer tmr
{
if (counter1 < 5) {
setTimer(tmr, 100); // Change the timer interval to 100ms after transmitting 0xAA 5 times
write (" this is key sending AA with 100");
senda.dlc=8;
senda.byte(1)=0xAA;
senda.byte(2)=0xAA;
senda.byte(3)=0xAA;
senda.byte(4)=0xAA;
senda.byte(5)=0xAA;
senda.byte(6)=0xAA;
senda.byte(7)=0xAA;
output(senda);
}
senda.byte(0) = (senda.byte(0))+5;
counter1++;
}
10. Write A CAPL Script to create a menu-based program on press of Keys for SID 11 and SID 28.
/*@!Encoding:65001*/
variables
{
message 0x779 senda;
message 0x778 sendc;
}
on start
{
write(" Press a for start SID 11 hard reset");
write(" Press b for start SID 11 soft reset");
write(" Press c for start SID 28 Rx Tx Enable");
write(" Press f for start SID 28 Rx Enable Tx disable");
write("hi");
write("hi");
write("hi my first message");
}
on key 'a'
{
write (" this is key Start Diagnotic SID11 hard reset ");
senda.dlc=8;
senda.byte(0)=0x02;
senda.byte(1)=0x11;
senda.byte(2)=0x01;
senda.byte(3)=0x00;
senda.byte(4)=0x00;
senda.byte(5)=0x00;
senda.byte(6)=0x00;
senda.byte(7)=0x00;
output(senda);
write ( " message sent)");
}
on key 'b'
{
write (" this is key Start Diagnotic SID11 soft reset ");
senda.dlc=8;
senda.byte(0)=0x02;
senda.byte(1)=0x11;
senda.byte(2)=0x03;
senda.byte(3)=0x00;
senda.byte(4)=0x00;
senda.byte(5)=0x00;
senda.byte(6)=0x00;
senda.byte(7)=0x00;
output(senda);
write ( " message sent)");
}
on key 'c'
{
write (" this is key Start Diagnotic SID28 enable Rx Tx");
senda.dlc=8;
senda.byte(0)=0x02;
senda.byte(1)=0x28;
senda.byte(2)=0x00;
senda.byte(3)=0x00;
senda.byte(4)=0x00;
senda.byte(5)=0x00;
senda.byte(6)=0x00;
senda.byte(7)=0x00;
output(senda);
write ( " message sent)");
}
on key 'f'
{
write (" this is key Start Diagnotic SID28 enable Rx disable Tx");
senda.dlc=8;
senda.byte(0)=0x02;
senda.byte(1)=0x28;
senda.byte(2)=0x01;
senda.byte(3)=0x00;
senda.byte(4)=0x00;
senda.byte(5)=0x00;
senda.byte(6)=0x00;
senda.byte(7)=0x00;
output(senda);
write ( " message sent)");
}
on key 'z'
{
write (" this is key c");
senda.dlc=8;
senda.byte(0)=0xcc;
senda.byte(1)=0x11;
senda.byte(2)=0x22;
senda.byte(3)=0x33;
senda.byte(4)=0x44;
senda.byte(5)=0x55;
senda.byte(6)=0x66;
senda.byte(7)=0x77;
output(senda);
write ( " message sent)");
}
on message 0x779
{
write("message received");
sendc.dlc=8;
if ( this.byte(0) == 0x02)
{
if ( this.byte(1) == 0x11)
{
sendc.byte(0)=0x02;
sendc.byte(1)=0x51;
if ( this.byte(2) == 0x01)
sendc.byte(2)=0x01;
else if ( this.byte(2) == 0x03)
sendc.byte(2)=0x03;
sendc.byte(3)=0x00;
sendc.byte(4)=0x00;
sendc.byte(5)=0x00;
sendc.byte(6)=0x00;
sendc.byte(7)=0x00;
output(sendc);
write ( " message sent postive respone)");
}
else if ( this.byte(1) == 0x28)
{
sendc.byte(0)=0x02;
sendc.byte(1)=0x68;
if ( this.byte(2) == 0x00)
sendc.byte(2)=0x00;
else if ( this.byte(2) == 0x01)
sendc.byte(2)=0x01;
sendc.byte(3)=0x00;
sendc.byte(4)=0x00;
sendc.byte(5)=0x00;
sendc.byte(6)=0x00;
sendc.byte(7)=0x00;
output(sendc);
write ( " message sent postive respone)");
}
}
else {
sendc.byte(0)=0x03;
sendc.byte(1)=0x7f;
sendc.byte(2)=0x10;
sendc.byte(3)=0x13;
sendc.byte(4)=0x00;
sendc.byte(5)=0x00;
sendc.byte(6)=0x00;
sendc.byte(7)=0x00;
output(sendc);
}
}
How to install Canoe demo tool and write CAPL programs are explained. The capl programs and questions are attached kindly go through them.
CAPL is a procedural language whereby the execution of program blocks is con-trolled by events. These program blocks are known as event procedure. Data types available for variables include integers (dword, long, word, int, byte, char), floating point numbers (float and double).
CAPL is an acronym for Communication Access Programming Language, which is a programming language used in Vector testing tools chain. It is used to create:
Simulation network nodes
Measurement, analysis components
Testing modules
CAPL:
CAN Access Programming Language
CAPL Programming:
The CAN Access Programming Language CAPL is a C-like programming language,
which allows you to program CANoe for individual applications.
Introduction to CAPL:
CAPL, the CAN Access Programming Language, allows you to quickly develop code that makes CANalyzer or CANoe simulations more powerful.
CAPL is a procedural language whereby the execution of program blocks is con-trolled by events. These program blocks are known as event procedures.
The program code that you define in event procedures is executed when the event occurs.
For example, you can send a message on the bus in response to a key press (on key), track the occurrence of messages on the bus (on message), or execute certain actions cyclically (on timer).