如何在CANoe测试报告中通过CAPL插入信号/XCP读数变化图表?
Great question! I’ve tackled this exact scenario a few times when building polished automated test reports in CANoe, so let’s walk through a step-by-step solution using CAPL.
核心思路
We’ll break this into three key parts:
- Capture and store the signal/XCP data over time during your test
- Use CANoe’s built-in Report API to generate a line graph from the collected data
- Insert the graph directly into your test report alongside your existing
teststeppasstext output
Step 1: Capture Signal/XCP Data
First, you need to log the timestamp, target signal value, and XCP reading at regular intervals. Use global arrays to store this data, and a timer or signal trigger to capture it.
// Global variables to store collected data (adjust array size based on your test duration) long dataSampleCount = 0; double timestamps[2000]; // Store time in seconds double targetSignal[2000]; // Replace with your signal's data type if needed double xcpReading[2000]; // Replace with your XCP measurement's data type // Timer to capture data at 10ms intervals (adjust frequency as needed) on timer 10ms { if (dataSampleCount < 2000) { timestamps[dataSampleCount] = timeNow() / 1000; // Convert CANoe's ms timestamp to seconds targetSignal[dataSampleCount] = getSignal("YourTargetSignalName"); // Replace with your signal xcpReading[dataSampleCount] = XCP_GetValue("YourXCPMeasurementName"); // Replace with your XCP item dataSampleCount++; } }
Step 2: Generate Graph with CAPL Report API
CANoe’s Report API has dedicated functions to create and customize graphs. Create a reusable function to build your graph, add curves, and style it to your needs.
void createAndInsertDataGraph() { // Create a new graph with title and axis labels long graphHandle = ReportCreateGraph("Signal vs XCP Reading Trend", "Time (s)", "Value"); // Add the signal curve (blue line) ReportGraphAddCurve(graphHandle, "Vehicle Speed", timestamps, targetSignal, dataSampleCount, 0x0000FF); // Add the XCP reading curve (red line) ReportGraphAddCurve(graphHandle, "Engine Torque (XCP)", timestamps, xcpReading, dataSampleCount, 0xFF0000); // Optional: Customize graph style ReportGraphSetStyle(graphHandle, GRAPH_STYLE_LINE); // Use line graph (alternatives: GRAPH_STYLE_POINT) ReportGraphSetLegendPosition(graphHandle, LEGEND_POSITION_TOP_RIGHT); ReportGraphSetGrid(graphHandle, GRID_STYLE_FULL); // Show grid lines for readability // Insert the graph into the current test step's report ReportInsertGraph(graphHandle, REPOS_INSERT_BELOW); // Clean up the graph handle to free resources ReportDestroyGraph(graphHandle); }
Step 3: Integrate with teststeppass and Test Flow
Now tie this into your test case: start data collection, run your test actions, output your text summary with teststeppass, then insert the graph.
testcase TC_SignalXCP_Correlation() { // Start data collection timer setTimer(10ms, 0); // 0 = repeat timer indefinitely // Execute your test logic (e.g., simulate driver input, wait for conditions) outputSignal("AcceleratorPedal", 75); wait(6000); // Wait 6 seconds to collect data // Stop data collection killTimer(10ms); // Output your existing text summary with teststeppass teststeppass("Successfully captured %d pairs of Vehicle Speed and Engine Torque (XCP) data points", dataSampleCount); // Generate and insert the graph into the report createAndInsertDataGraph(); // Reset sample count for subsequent test cases dataSampleCount = 0; }
Key Notes & Troubleshooting
- Array Size: Make sure your global arrays are large enough to hold all samples for your test duration. If you’re testing for 1 minute at 10ms intervals, you’ll need 6000 samples.
- XCP Configuration: Ensure your XCP measurement is properly configured in CANoe’s XCP setup (connected to the ECU, measurement item enabled).
- Report Settings: Enable the report feature in CANoe’s
Options > Reportand set your desired report format (HTML, PDF, etc.)—the graph will be embedded directly. - Data Types: Adjust the array data types (e.g.,
longinstead ofdouble) if your signal/XCP reading uses integer values.
内容的提问来源于stack exchange,提问作者Hitesh Anand




