> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/hypersim/configure-ios/communication-protocol-ios/can/can-two-channels-example.md).

# CAN Two Channels Example

***

### if: space.vars.RTLAB

## CAN Two Channels Example

### Description <a href="#description" id="description"></a>

The **CAN\_2\_channels** example can be created by starting a new RT‑LAB project. From the menu bar, select **File > New > RT‑LAB Project**. Enter a name and location for your project, then click **Next**. From the available templates list, navigate to **IO > Generic > CAN > Kvaser** and select **CAN\_2\_channels**, then click **Finish**. This example demonstrates how to use the **CAN interface** to exchange CAN messages between multiple CAN channels using a **physical loopback configuration**. The example illustrates message transmission and reception, cyclic and non‑cyclic messages, dynamic CAN identifiers, and CAN operation.

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-a36a56cb1ee848e5c566cddb896ccb76b494b0be%2FDR-rtlab-can-ex.png?alt=media" alt="" width="383"><figcaption></figcaption></figure>

Two CAN channels are used in this example. Channels are connected in loopback to allow messages transmitted on one channel to be received on another channel within the same simulator.

### Requirements

The simulator must be equipped with a **Kvaser PCIe CAN interface card (**[**OP3411**](https://www.opal-rt.com/docs/pcie-cards-and-connector-kits/pcie-cards/op3411-kvaser-pcie-can-bus-kits.md)**)** providing at least **two CAN channels**. Physical CAN **loopback connections** must be installed between:

* **Channel 1 and Channel 2**

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-ca8dca8c143626db3c231ad33609be0255e0c496%2FDR-rtlab-can-ex2.jpg?alt=media" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
The CAN loopback cable shown above includes **internal 120 Ω termination resistors at both ends**, providing proper bus termination for loopback operation.
{% endhint %}

[Verify that an active RT-LAB license](https://www.opal-rt.com/docs/hypersim/licensing-reference/simulator-license.md) with the following features is installed on the simulator:

<table><thead><tr><th width="245">Feature Name</th><th width="175">Required Status</th><th width="320">Description</th></tr></thead><tbody><tr><td>CAN</td><td>enabled</td><td>Enables CAN</td></tr><tr><td>CAN_CHANNEL_NB</td><td>2 enabled (or more)</td><td>Number of activated CAN channels</td></tr></tbody></table>

### Detailed explanation

In this example, **CAN Channel 1** is configured to **transmit a non‑cyclic message** (`Bus_1 / Node_1 / Message_1`) with a fixed **CAN ID 1176**, while **CAN Channel 2** is configured to **receive** the same message using the same CAN identifier. The message is transmitted only when the **Enable Message** signal is asserted and, when enabled, is sent at every model time step.

**CAN Channel 2** is also configured to **transmit a second message** (`Bus_Dbc / MCU_2 / MCU_DOOR_LOCK`) using a **dynamic CAN ID**. Dynamic IDs allow the CAN identifier of the message to be modified at runtime from the console during model execution. This message is configured as **cyclic**, with a **transmit rate of 5 ms**. Cyclic transmission is enabled by selecting **Enable Cyclic Transmission** and setting the **Transmit Rate** parameter. The message is transmitted only when the **Enable Message** signal is asserted and, when enabled, is sent at every model time step.

To receive this cyclic message, **CAN Channel 1** is configured to receive the same message (`Bus_Dbc / MCU_2 / MCU_DOOR_LOCK`) in **promiscuous mode**. In promiscuous mode, all CAN frames received on the channel are forwarded to the model, regardless of their CAN identifier.

With this configuration, **Channel 1 receives messages transmitted by Channel 2**, and **Channel 2 receives messages transmitted by Channel 1**, demonstrating both fixed‑ID and dynamic‑ID communication, as well as cyclic and non‑cyclic message handling.

#### Model preparation and configuration

1. Review and adjust CAN interface parameters as desired.
2. Build the CAN\_2\_channels model.
3. Load the model and verify that all CAN interface connections are correctly established.
4. Execute the model.

### Simulation and results

Once the simulation is running, the CAN channels begin exchanging messages through the physical loopback connections.

The **Console subsystem** allows runtime interaction with the CAN interface, including modifying dynamic CAN IDs, updating transmitted data, enabling or disabling message transmission and reception, and monitoring received data and status information. Data transmitted on one channel can be observed as received on its paired channel, confirming correct CAN configuration and operation.

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-f05ae3876e06905b26f710a715aaa9833a999b49%2FDR-rtlab-can-ex3.png?alt=media" alt=""><figcaption></figcaption></figure>

Successful execution of this example validates correct CAN channel configuration, message timing, dynamic identifier handling, and CAN communication using RT‑LAB.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.opal-rt.com/docs/hypersim/configure-ios/communication-protocol-ios/can/can-two-channels-example.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
