Advertisement
Responsive Ad Slot (Vector Toolchains & Embedded Certifications)
🚗 Automotive System Focus: CANoe Measurement Controller

Simulation Lifecycle & System Variable Integration

In modern Vector CANoe configurations, tests interact with System Variables (`@sysvar`) to control measurement states, GUI panels, and virtual I/O channels. Functions like `stop()`, `start()`, `output()`, and `trace()` give scripts comprehensive control over the simulation environment.

Overview & Key Concepts

In CAPL (CANoe/CANalyzer Programming Language) scripting, specific functions are provided to interact with and control CANoe or CANalyzer environments. CAPL is a high-level programming language used to simulate, test, and diagnose automotive networks like CAN (Controller Area Network), LIN, Ethernet, and FlexRay in CANoe or CANalyzer software. CAPL scripting allows you to automate tasks, process signals, interact with external systems, and implement more complex test logic.

Overview of CANoe/CANalyzer-Specific Functions in CAPL

These functions in CAPL enable you to interact with CANoe or CANalyzer features directly. They are essential for tasks such as simulating nodes, sending/receiving messages, working with CAN signals, and synchronizing events within the simulation environment.

Some of the key categories of functions include

CAN Bus Communication

Signal Processing

Logging and Monitoring

Timing and Synchronization

Environment Control

CAN Bus Communication Functions

CAPL provides several functions to handle CAN bus communication, such as sending and receiving messages, as well as manipulating bus parameters.

a) output()

Sends a message on the CAN bus.

Example

CAPL CAPL - Example
message myMessage;
myMessage.byte(0) = 0x01;  // Setting the first byte of the message
output(myMessage);  // Sending the message

This sends a message called myMessage to the CAN network with data that is manipulated inside the script.

b) setTimer()

Sets a timer to trigger after a specified period. Often used in combination with event-driven simulations.

Example

CAPL CAPL - Example
variables
{
msTimer myTimer;
}
on start
{
setTimer(myTimer, 1000);  // Set the timer for 1000 ms (1 second)
}
on timer myTimer
{
output(myMessage);  // Send the message after 1 second
}

Here, after 1 second, the message is sent to the bus.

c) getMessage()

Receives messages from the CAN bus.

Example

CAPL CAPL - Example
message receivedMessage;
on message CAN1
{
receivedMessage = this;  // Store the received message in receivedMessage variable
write("Received message: %s", receivedMessage);
}

This example listens for messages on the CAN1 channel, stores them in the receivedMessage variable, and writes the message content.

Signal Processing Functions

These functions help interact with signals within a CAN message, which are typically used to control or monitor device states in automotive networks.

a) signal

You can use signals to read or modify individual values inside a CAN message.

Example

CAPL CAPL - Example
message myMessage;
on start
{
myMessage.byte(0) = 0x55;  // Set byte 0 of myMessage to 0x55
myMessage.signal("mySignal") = 0x01;  // Set a specific signal within the message to 0x01
output(myMessage);
}

This modifies the signal inside the CAN message before sending it to the bus.

b) signal with conditional check

You can also perform conditional checks on signals to react to specific values.

Example

CAPL CAPL - Example
on message CAN1
{
if (this.signal("engineSpeed") > 2000)
{
output(engineControlMessage);
}
}

In this example, the script checks if the engine speed exceeds 2000 RPM (engineSpeed signal) and sends a control message accordingly.

Logging and Monitoring Functions

CAPL allows you to interact with log files or monitors for debugging or testing purposes.

a) write()

Writes output to the log window, which is useful for debugging.

Example

CAPL CAPL - Example
on start
{
write("Simulation Started!");
}

This writes "Simulation Started!" to the log when the simulation starts.

b) trace()

Traces a specific signal value.

Example

CAPL CAPL - Example
on message CAN1
{
trace(this.signal("engineSpeed"));
}

This function traces the value of the engineSpeed signal from the received message and displays it in the trace window.

c) log()

Logs a specific value to a log file for analysis.

Example

CAPL CAPL - Example
on message CAN1
{
log(this.signal("engineSpeed"));
}

This writes the value of the engineSpeed signal into the log file every time the message is received.

Timing and Synchronization Functions

For simulations that require time-based synchronization, such as real-time behavior testing, CAPL provides timing functions.

a) wait()

Waits for a specific amount of time before proceeding with the script's execution.

Example

CAPL CAPL - Example
on start
{
wait(1000);  // Wait for 1 second
output(myMessage);
}
The script waits for 1 second before sending the message.

b) setTimer() and stopTimer()

Sets a timer and stops it when needed.

Example

CAPL CAPL - Example
variables
{
msTimer timer1;
}
on start
{
setTimer(timer1, 500);  // Set a timer for 500 ms
}
on timer timer1
{
output(myMessage);
stopTimer(timer1);  // Stop the timer after sending the message
}

This sets a timer for 500 ms and sends the message after the timer expires, then stops the timer.

Environment Control Functions

CAPL also allows controlling the CANoe/CANalyzer environment, for instance, controlling the network traffic, adjusting simulation parameters, and more.

a) start()

Starts a specific simulation node (e.g., a CAN node).

Example

CAPL CAPL - Example
on start
{
start("CAN_Node");  // Start the simulation for the CAN_Node
}

This command starts a CAN node defined in your CANoe environment.

b) stop()

Stops a simulation node or a process.

Example

CAPL CAPL - Example
on stop
{
stop("CAN_Node");  // Stop the CAN_Node simulation
}
This command stops the CAN node during the script execution.

c) suspend() and resume()

These functions allow you to suspend or resume a simulation.

Example

CAPL CAPL - Example
on timer myTimer
{
suspend();  // Suspend the simulation
write("Simulation suspended.");
}
on key 'r'  // Resume the simulation with a key press
{
resume();  // Resume the simulation
write("Simulation resumed.");
}

This example suspends the simulation after a timer expires and allows it to be resumed with a key press.

Conclusion

CAPL scripting in CANoe/CANalyzer provides a rich set of functions to interact with and manipulate CAN networks, simulate complex behaviors, control environment parameters, and process data. The functions described above are just a few examples, and there are many more available for handling different types of communication protocols and system interactions in the automotive industry. These capabilities make CAPL a powerful tool for automating test scenarios, debugging, and simulating real-time network behavior in CANoe or CANalyzer.

⚠️ Common Pitfalls & CANoe Troubleshooting Tips
  • Accessing System Variables requires proper namespace syntax: `@sysvar::Namespace::VariableName` or using `sysGetVariableInt()` APIs.
  • Calling `stop()` halts simulation immediately; ensure all required log files are flushed before calling it.
📝 Concept Mastery Assessment
12 Questions Score: 0 / 0

Select your answer for each question below to receive immediate correctness evaluation and in-depth technical rationale.

Question 1 of 12
What is the primary difference in CAPL capability between CANalyzer and CANoe?
Explanation
CANoe is the full ECU network development and simulation environment; CANalyzer focuses on bus monitoring, logging, and analysis.
Question 2 of 12
Which CANoe feature allows building standalone interactive graphical dashboards with gauges, buttons, and displays?
Explanation
Panel Designer creates visual HMI panels connected to system variables and environment variables.
Question 3 of 12
What is the purpose of CANoe Option .AMD / .AUTOSAR?
Explanation
CANoe.AMD/AUTOSAR provides native support for ARXML system descriptions, PDUs, and diagnostic communication.
Question 4 of 12
Which built-in function stops the entire CANoe measurement simulation programmatically from CAPL?
Explanation
'stop();' commands CANoe to gracefully conclude simulation measurement, triggering 'on stop' handlers.
Question 5 of 12
What is the CANoe Test Feature Set (TFS)?
Explanation
TFS provides structured test case declarations, verification functions, and automated test report generators.
Question 6 of 12
Which function sets the overall verdict of a test module in CANoe?
Explanation
Test Feature Set functions update the test verdict (Pass, Fail, Inconclusive, Error) in the test report.
Question 7 of 12
What file format is generated by CANoe Test Service Library upon test completion?
Explanation
CANoe produces comprehensive XML test results transformed with XSL stylesheets into professional HTML audit reports.
Question 8 of 12
How do you load a diagnostic security access seed-and-key DLL in CANoe?
Explanation
Diagnostic configurations in CANoe link security algorithms (Seed & Key DLLs) for UDS security access levels.
Question 9 of 12
What is CANoe.DiVa used for?
Explanation
CANoe.DiVa automatically generates and executes comprehensive diagnostic validation test suites.
Question 10 of 12
What function injects an ECU reset command via UDS diagnostics in CAPL?
Explanation
Diagnostic objects (diagRequest) format and transmit ISO 14229 UDS services (0x11 = ECU Reset).
Question 11 of 12
What is the purpose of the CANoe Trace Filter feature?
Explanation
Trace filters allow engineers to focus on relevant messages and signals while all traffic is captured in the background.
Question 12 of 12
What function pauses execution in a CAPL Test Module for a specified time delay?
Explanation
'testWaitForTimeout(ms)' pauses execution in test modules while allowing CANoe simulation time to advance normally.
0 / 0 (0%)
Great job! Review the questions above and proceed when ready.
🛠️ Hands-on Automotive Challenge: Automated Test Suite Stop Condition

Write a script that monitors a system variable `@sysvar::TestSuite::TestErrorCount`. If the error count reaches 3, print a test aborted banner to the Write window and stop the CANoe measurement automatically using `stop()`.

Verified CAPL implementation:

CAPL Solution - Automated Test Suite Stop Condition
on sysvar TestSuite::TestErrorCount {
  if (@TestSuite::TestErrorCount >= 3)
  {
    writeLineEx(0, 3, "===============================================");
    writeLineEx(0, 3, "TEST ABORTED: Critical error threshold reached!");
    writeLineEx(0, 3, "Total Errors: %d. Terminating measurement run.", @TestSuite::TestErrorCount);
    writeLineEx(0, 3, "===============================================");
    stop(); // Halt CANoe simulation
  }
}
Advertisement
Responsive Ad Slot (Automotive Embedded Systems Career Resources)