CAN Message Simulation: A Practical Automotive Engineering Guide
CAN message simulation is used to reproduce network traffic, stimulate an ECU, model a missing network participant or test how a system responds to defined communication conditions. A useful simulation must get more than the identifier right: frame format, DLC, payload, signal encoding, timing, message ownership and shutdown behavior all matter.
This article explains the practical lifecycle of a simulated CAN message using CAPL-style examples. Exact syntax and available APIs depend on the CAPL environment and installed tool version. Treat the code as a learning pattern and confirm it against the project database and tool documentation before using it in a real test configuration.
1. What does CAN message simulation mean?
A simulated CAN message is a frame generated by a software-based network participant rather than by the real ECU that normally owns that message. A simulation node can:
- Transmit a message periodically using a timer.
- Transmit a message in response to a received frame or another event.
- Change payload bytes or database-defined signals before transmission.
- Receive frames and update its internal simulation state.
- Model counters, state transitions and selected fault conditions.
- Stop transmission and reset state when measurement ends.
Simulation is commonly used when an ECU is not yet available, when a test needs controlled inputs, or when a specific network condition must be reproduced repeatedly.
Simulation versus real ECU communication
| Activity | Description |
|---|---|
| Real ECU transmission | A physical ECU sends a frame through its network interface |
| Message simulation | A configured software node generates a frame |
| Stimulation | A simulated frame or signal is used as an input to another ECU |
| Monitoring | A measurement setup observes frames without necessarily transmitting them |
| Automated test | Stimulus and observed behavior are evaluated against defined requirements |
A simulation node should have an explicit responsibility. Do not allow it to unintentionally compete with a real ECU for ownership of the same message.
2. CAN message structure to understand before simulation
A CAN data frame contains an arbitration field, control information, a data field, CRC, acknowledgement and frame-ending bits. For message simulation, engineers most often configure or verify the identifier, frame format, DLC and payload.
| Field | Engineering significance |
|---|---|
| Identifier | Identifies the message and participates in arbitration priority |
| Frame format | Standard 11-bit identifier or extended 29-bit identifier |
| RTR / frame type | Distinguishes data and remote-frame behavior in Classical CAN; CAN FD uses data frames and does not support remote frames |
| DLC | Encodes the data length according to the applicable CAN format |
| Data field | Carries the raw payload bytes |
| CRC and ACK | Handled by the CAN protocol controller; not normally populated manually in an application message object |
For Classical CAN, the data field can contain up to 8 bytes. CAN FD supports up to 64 data bytes. The configured frame type and payload length must be supported by the network and every relevant controller.
Raw bytes and decoded signals
A database such as a DBC maps message identifiers and payload bits to named signals. A signal definition can specify start bit, length, byte order, signedness, factor, offset and unit.
For example, a raw payload byte may represent a physical value using:
The exact start-bit convention and byte-order interpretation must follow the database format and tool implementation. Always verify the decoded value against a known raw payload.
3. Simulation architecture and message lifecycle
A common message lifecycle is:
- Initialize simulation state when measurement starts.
- Configure an initial payload or signal value.
- Start a timer or wait for a triggering event.
- Update the message data.
- Transmit the message.
- Receive and process other messages as required.
- Cancel timers and reset state when measurement stops.
The diagram describes a functional pattern, not a mandatory software architecture. Map each step to the actual simulation node and test configuration.
For every simulated message, document:
- Message identifier and standard/extended format.
- Data length and expected payload layout.
- Transmitting node and channel.
- Trigger type and nominal cycle time, if periodic.
- Initial values and update rules.
- Counter, checksum or freshness behavior, if required by the interface.
- Timeout and invalid-data behavior expected by consumers.
- Conditions for starting and stopping transmission.
4. CAPL message declaration and initialization
CAPL is an event-driven language used in supported automotive network simulation and test environments. A message object represents a CAN message that can be populated and transmitted by the simulation.
An illustrative declaration pattern is:
variables
{
message 0x321 StatusMsg;
msTimer statusTimer;
byte counter = 0;
}
The identifier and message declaration syntax should be checked against the active database and CAPL version. In a database-driven configuration, using the symbolic message definition is generally preferable because the database provides the intended message and signal mapping.
Initialize the state when measurement starts:
on start
{
counter = 0;
setTimer(statusTimer, 100);
}
The 100 ms interval is only an example. Use the message cycle time and test requirement defined by the project.
5. Cyclic CAN message transmission
A cyclic message is transmitted repeatedly at a configured interval. This is useful for periodic ECU inputs such as vehicle state, sensor status or simulated body signals.
Example: transmit a message every 100 ms
variables
{
message 0x321 StatusMsg;
msTimer statusTimer;
byte counter = 0;
}
on start
{
counter = 0;
setTimer(statusTimer, 100);
}
on timer statusTimer
{
StatusMsg.dlc = 8;
StatusMsg.byte(0) = counter;
StatusMsg.byte(1) = 0x01;
output(StatusMsg);
counter++;
setTimer(statusTimer, 100);
}
This is an illustrative CAPL-style example. Check the message-object declaration, byte access and timer APIs supported by the installed CAPL runtime. If the message is database-defined, prefer the configured symbolic message and signals where possible.
What the example does
- Declares a message object and a timer.
- Initializes the counter when measurement starts.
- Starts the timer.
- Sets the payload values when the timer expires.
- Sends the message using
output(). - Increments the counter and schedules the next transmission.
A production simulation should define counter rollover, initial payload values, any checksum algorithm, transmission enable/disable conditions and cleanup behavior. Do not assume that a counter or checksum is required unless the network specification defines it.
6. Event-triggered transmission
Not every message needs to be sent periodically. Some messages are generated when a state changes, a request arrives or a test action occurs.
For example, a simulated ECU may transmit a response after receiving a request message. An illustrative event pattern is:
on message 0x456
{
// Evaluate the received request and update simulation state.
// Populate the response message according to the project definition.
// Transmit only when the specified preconditions are satisfied.
}
The event handler should check more than the identifier when the test requires it. Relevant checks may include:
- Expected DLC and frame format.
- Request type or signal value.
- Validity bits, counters or checksum status where applicable.
- ECU operating state and test preconditions.
- Whether the response is permitted at this point in the test.
Avoid placing long blocking operations in measurement event handlers. Keep event processing bounded and use timers or test-control mechanisms for delayed actions.
7. Receiving and analyzing CAN messages
A simulation node can also monitor incoming messages and update its internal state. Receiving a frame does not automatically mean its application data is valid.
For a received message, consider checking:
- Identifier and frame format.
- DLC and payload layout.
- Signal ranges and enumerated values.
- Alive counter or rolling-counter sequence, if specified.
- Checksum or end-to-end protection, if specified.
- Message freshness and expected cycle time.
- Operating-state preconditions.
A frame can be present in the trace but still contain stale, invalid or implausible data. Keep raw-frame evidence so that database decoding can be independently checked.
8. Raw-byte access versus database-defined signals
There are two common ways to populate a simulated message.
Raw-byte approach
Raw-byte access is useful when testing exact payload patterns, reserved bits, boundary values or malformed frames. It requires careful control of byte order and bit positions.
Illustrative pattern:
on timer statusTimer
{
StatusMsg.dlc = 8;
StatusMsg.byte(0) = 0x12;
StatusMsg.byte(1) = 0x34;
output(StatusMsg);
}
Symbolic-signal approach
When a communication database is loaded and the message is mapped correctly, symbolic signal access can make test logic easier to understand. The exact CAPL syntax depends on the database and tool configuration.
Illustrative pattern:
// Conceptual example only:
// StatusMsg.SomeSignal = desiredValue;
// output(StatusMsg);
Use symbolic signals for application-oriented tests and raw bytes when the test specifically targets payload encoding. For either approach, verify the transmitted bytes in the trace.
9. CAN arbitration and competing simulated messages
CAN uses non-destructive bitwise arbitration. A node that transmits a recessive bit but observes a dominant bit loses arbitration and stops transmitting; the winning frame continues.
For two standard-format identifiers, the lower numerical identifier has higher priority when comparing the identifier bits under the same relevant frame conditions.
Arbitration bit b10 b9 b8 b7 b6 b5 b4 ...
Node A, ID 0x100 0 0 1 0 0 0 0 ...
Node B, ID 0x180 0 0 1 1 0 0 0 ...
Observed bus 0 0 1 0 0 0 0 ...
^
Node B sends recessive 1,
observes dominant 0 and loses arbitration
This symbolic example assumes both nodes begin arbitration together and use standard identifiers. A complete arbitration comparison includes the relevant frame-format and control bits. Standard and extended frames sharing the same 11-bit base identifier require special care because the standard frame wins at the relevant arbitration bit.
Avoid duplicate message ownership
A common bench problem occurs when a real ECU and a simulation node both transmit the same identifier. Depending on timing and payload, this can create arbitration interactions, unexpected data or error behavior.
Maintain a message ownership table:
| Message | Intended transmitter | Purpose |
|---|---|---|
| Vehicle speed | Real powertrain ECU or designated simulator | Provide vehicle-speed input |
| Ignition state | Bench simulator | Set ECU operating condition |
| ECU status | ECU under test | Observe actual ECU output |
Only one source should own a message unless the test explicitly evaluates arbitration or competing transmitters.
10. Verification matrix for message simulation
| Test area | Stimulus or condition | Evidence to capture |
|---|---|---|
| Nominal transmission | Valid operating state | Identifier, DLC, payload and cycle time |
| Boundary values | Minimum and maximum signal values | Correct raw encoding and decoded value |
| Invalid input | Missing, malformed, stale or out-of-range data | Rejection, diagnostic state or fallback |
| Timing | Delayed event or missed deadline | Timestamped latency and timeout verdict |
| Reset / restart | Restart during initialization or active operation | Correct state recovery and timer behavior |
| Communication fault | Bus-off, missing frame or invalid frame as applicable | Error status, recovery and application behavior |
| Resource stress | High bus load or competing traffic | Timing and behavior under load |
| Regression | Previously fixed defect and nominal scenarios | Repeatable verdict against the baseline |
Verify channel and database assignment, message direction, cycle time, initial values, counter/checksum behavior where specified, timeout behavior, bus load and simulation ownership. Inspect the trace to confirm the actual transmitted bytes.
11. Failure analysis and common implementation traps
| Symptom | Possible cause | Checks |
|---|---|---|
| No simulated frame appears | Timer not started, node not active, wrong channel or transmit configuration | Measurement state, event execution, node assignment and channel |
| Wrong identifier or frame format | Incorrect message declaration or database mapping | Compare configuration and trace |
| Wrong decoded signal | Incorrect DBC revision, start bit, byte order, factor or offset | Compare raw bytes with database definition |
| Unexpected payload | Initialization or update logic is incorrect | Inspect state transitions and byte assignments |
| Duplicate messages | Real ECU and simulator both transmit the same message | Check message ownership |
| Incorrect cycle time | Timer scheduling or load effects | Inspect timestamp deltas and measurement conditions |
| ECU ignores simulated input | Invalid DLC, payload, checksum, counter, timeout or operating state | Compare against ECU interface requirements |
| Test passes inconsistently | Race conditions, weak synchronization or undefined preconditions | Make stimulus and verdict timing explicit |
Systematic debugging sequence
- Confirm ECU power, reset, wiring and network interface.
- Verify the measurement channel and CAN/CAN FD configuration.
- Confirm the simulation node is active and assigned to the intended channel.
- Check that the timer or event handler executes.
- Inspect the raw trace for identifier, frame format, DLC and payload.
- Compare raw bytes with the database signal definition.
- Check message ownership and bus load.
- Verify the ECU's operating state and input validity requirements.
- Save the configuration, trace and logs before changing the implementation.
- Add a regression test after correcting the root cause.
12. Engineering checklist
- Message identifier and standard/extended format are correct.
- Classical CAN or CAN FD format is selected correctly.
- DLC and payload length match the interface definition.
- Signal start bits, lengths, byte order, factor and offset are verified.
- Transmission trigger and cycle time are defined.
- Initial values and update behavior are deterministic.
- Counter and checksum behavior follow the project specification, if applicable.
- Real ECU and simulation-node message ownership is clear.
- Timeout, invalid-data and shutdown behavior are defined.
- Raw traces and test verdicts are retained.
- Hardware, software, database and tool versions are recorded.
13. Check your understanding
- What is the difference between cyclic and event-triggered CAN message transmission?
- Why should an engineer inspect raw payload bytes when a decoded signal looks incorrect?
- What does
output()do in the illustrative CAPL message lifecycle? - Why should a simulation node not unintentionally transmit a message already owned by a real ECU?
- Which checks should be performed before treating a received frame as valid?
- Why must counter and checksum behavior be taken from the project communication specification rather than assumed?
Suggested answers
- Cyclic transmission is scheduled repeatedly at a defined interval; event-triggered transmission occurs in response to a specified event or condition.
- A database mapping error can produce an incorrect decoded value even when the raw frame is correct.
- It requests transmission of the configured message object through the simulation environment.
- Competing transmitters can cause arbitration interactions, unexpected payload behavior or communication errors.
- Check identifier, frame format, DLC, payload layout, signal ranges, counter/checksum where specified, freshness and operating-state preconditions.
- These mechanisms are project-specific; not every CAN message uses an application counter or checksum.
Related articles
- CAPL Functions and Events
- CAPL Programming Tutorial
- Python for CAN Communication
- CAPL Test Automation: A Practical Automotive Engineering Guide
- CANoe Testing Concepts: A Practical Automotive Engineering Guide
Further reading
- ASAM — Standards and test automation ecosystem
- CAN in Automation — CAN knowledge
- ISO 11898-1:2024 — CAN data link layer
Use the standard edition, communication database, OEM network specification and CAPL documentation applicable to the target project. Confirm tool-version-specific syntax and behavior before using an example in a production test configuration.
