# Modbus Connect

This function block establishes a Modbus TCP connection to a remote device and provides a reusable `Modbus Client` output that other blocks can use to perform reads/writes.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

This function block does not have any inputs.

## 📤 Outputs <a href="#outputs" id="outputs"></a>

`Modbus Client` A connected Modbus client reference that can be fed into communication blocks to read or write registers.

## 🕹️ Controls <a href="#controls" id="controls"></a>

`IP Address` Enter the Modbus TCP server IP address (for example 192.168.0.10).

`TCP Port` Enter the Modbus TCP port (default is commonly 502).

## ⚙️ Running mechanism <a href="#running-mechanism" id="running-mechanism"></a>

* When evaluated, the block attempts to connect to the Modbus server at the address and port provided in the controls.
* If the address or port is changed, or if the connection drops, the block will attempt to reconnect automatically and continues to provide an updated `Modbus Client` output for other blocks.
* Other blocks receive the `Modbus Client` through the output socket and use it to perform communication tasks (reads/writes).

## 🎯 Features <a href="#features" id="features"></a>

* Persistent connection output so multiple blocks can share a single client.
* Automatic reconnection when address changes or the connection is lost.
* Simple UI controls for IP and port configuration.

## 📝 How to use <a href="#usage" id="usage"></a>

1. Set the `IP Address` and `TCP Port` in the controls.
2. Let the scenario run — the block will establish the connection and provide the `Modbus Client` on its output.
3. Connect the `Modbus Client` output to communication blocks that require it (for example read/write blocks) to perform Modbus operations.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

* To read data regularly, connect the `Modbus Client` output to the `Modbus Read` block and use a `Logic Input` or another trigger to control when reads happen.
* To write commands or values, feed the `Modbus Client` to the `Modbus Write` block and use a logic trigger to perform writes only when needed.
* Forward telemetry to remote systems by combining with `MQTT Publish` (connect output from a read block into `MQTT Publish`) for lightweight messaging.
* Save or log values by sending read outputs into `SQL-DB Operations` or `CSV Export` for persistent storage and later analysis.
* Use `Debug Input` or `Scope` to inspect values coming from read blocks during setup and troubleshooting.

(hint: recommended companion blocks — `Modbus Read`, `Modbus Write`, `Logic Input`, `MQTT Publish`, `SQL-DB Operations`, `CSV Export`, `Debug Input`, `Scope`)

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* Connection refused or timeouts — check the `IP Address` and `TCP Port` are correct and that the Modbus server is reachable on the network.
* Firewall or network rules — ensure the port used for Modbus TCP is allowed through firewalls on both ends.
* Multiple clients — if the server limits connections, avoid creating many simultaneous connections; share the provided `Modbus Client` output with other blocks.
* If connection appears unstable, verify the network quality and try a different network cable or switch port.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.augelab.com/function-blocks/input-output/communication/modbus-connect.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
