> 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/rt-lab/configure-ios/communication-protocol-ios/modbus-slave/modbus-slave-example.md).

# Modbus Slave Example

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

The **Modbus Slave** 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\_ > Modbus\_Slave** and select **Modbus Slave**, then click **Finish**. This example demonstrates how to use the Modbus slave interface to simulate two Modbus slave devices, one Modbus TCP slave and one Modbus RTU slave, that communicate with any industrial Modbus master over Ethernet (TCP) or serial links (RTU).

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-94cf6554c15ac02b8f5c8940739f2af93b771e69%2FDR-rtlab-modsl-ex.png?alt=media" alt="" width="422"><figcaption></figcaption></figure>

In this example, each simulated slave contains:

* **14 coils** (8 controlled by the model (addresses 0–7), 1 controlled by the master (address 40) and 5 controlled by both master and model (addresses 60–64))
* **8 discrete inputs** (addresses 10–17)
* **17 holding registers** (11 controlled by the model (addresses 20–30), 1 controlled by the master (address 50), and 5 controlled by both master and model (addresses 70–74))
* **4 input registers** (addresses 30–33)

## Requirements <a href="#requirements" id="requirements"></a>

In addition to the requirements stated in the Modbus Master **Requirements, Features & Limitations** section, this example requires a Modbus master device or software (e.g. [qModMaster](https://sourceforge.net/projects/qmodmaster/)) able to connect to the simulated Modbus slaves using the configured TCP or RTU communication parameters.

## Detailed explanation <a href="#detailedexplanation" id="detailedexplanation"></a>

This example illustrates how to simulate two independent Modbus slaves running concurrently in a real‑time model. The Modbus Slave interface uses a dedicated communication thread that runs in parallel with the real‑time simulation. All process data is exchanged through shared memory between the communication thread and the model, ensuring deterministic behavior without additional latency.

### Model preparation and configuration <a href="#modelpreparationandconfiguration" id="modelpreparationandconfiguration"></a>

1. Adjust the Modbus slave interface parameters (TCP port, IP address, serial settings, slave ID, etc.) as required. **Slave 1** uses **Modbus TCP** and **Slave 2** uses **Modbus RTU.**
2. Build the Modbus Slave model.
3. Load and execute the model.
4. Then start the external Modbus master.

## Simulation and results <a href="#simulationandresults" id="simulationandresults"></a>

Once communication is established, the Modbus master and Modbus slaves begin exchanging data.

Users can modify values in the slave console and confirm that the master receives the updated coil and register values. Conversely, changes made by the master to writable coils and registers are reflected in the model console according to the configured control mode (Model, Master, or Both).


---

# 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/rt-lab/configure-ios/communication-protocol-ios/modbus-slave/modbus-slave-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.
