> 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-master/modbus-master-example.md).

# Modbus Master Example

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

The **Modbus Master** 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\_Master** and select **Modbus Master**, then click **Finish**. This example demonstrates how to use the Modbus master interface to communicate with two Modbus slaves and exchange Modbus points, including coils, discrete inputs, holding registers, and input registers. The main objective of this example is to show how to configure the Modbus master interface, establish connections with Modbus TCP and RTU slaves.

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

In this example:

* The model receives 1 connected status (TCP only), 8 input coils, 8 discrete inputs, holding registers and 4 input registers, all displayed in the console subsystem.
* The model also sends 1 single coil, 1 single register, 5 multiple coils and 5 multiple registers for each slave, which can be modified from the console.

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

In addition to the requirements stated in the Modbus Master **Requirements, Features & Limitations** section, this example requires an external Modbus slave to provide data to the master interface.

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

This example illustrates how to configure the Modbus master to communicate with both a Modbus TCP slave and a Modbus RTU slave.

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

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

## 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 measurement values in the slave external tool, and observe the updated values in the model console, confirming proper data exchange between the two systems.


---

# 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-master/modbus-master-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.
