# Modbus Write

This function block sends values to a Modbus server using a provided Modbus client. Use it to write coils or holding registers from your scenario graph.

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

`Enable` This boolean input controls whether writing is performed. If not provided or False, the block will not attempt to write.

`Modbus Client` This input expects a client object produced by the `Modbus Connect` block. Provide a valid client to enable communication.

`Data` Generic data to write. Accepts a single value or a list (for writing multiple coils/registers).

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

This function block produces no outputs.

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

`Address` Enter the Modbus register/coils address to write to. Use integer values that match your device map.

`Data Type` Choose between `Coil` and `Holding Register` to select which Modbus resource type will be written.

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

* Supports writing single values or lists to multiple addresses when the device supports it.
* Lets you choose the target resource type with a simple dropdown: `Coil` or `Holding Register`.
* Respects the `Enable` input so writing can be controlled from logic or user inputs.
* Reports errors to the log if writing fails so you can diagnose connection or configuration problems.

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

When the block runs:

* If the `Enable` input is False or missing, no write is attempted.
* If no client is provided at `Modbus Client`, the block will not perform any write.
* When enabled with a valid client, the block sends the supplied `Data` to the address entered in `Address` using the selected `Data Type`.
* Errors (connection problems, invalid address, unsupported data) are reported to the log so you can act accordingly.

## 📝 Usage instructions <a href="#usage" id="usage"></a>

* Add a `Modbus Connect` block and connect its `Modbus Client` output to this block's `Modbus Client` input.
* Set `Address` to the register or coil address you want to write.
* Select `Data Type` as `Coil` for boolean/coils or `Holding Register` for numeric registers.
* Feed your data into the `Data` input (single value or list).
* Use a `Logic Input` or other control to toggle `Enable` when you want the write to occur.

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

* Use `Modbus Connect` to produce a reliable client and confirm the connection with `Modbus Read` before trying to write.
* Drive the `Enable` input from a `Logic Input` or a conditional block (for example `Equals` / `Greater`) so writes occur only under desired conditions.
* Prepare write values using `Number Input` or by assembling data with blocks like `String Merge` or `Data Write Global` / `Data Write Local` when you need to stage values.
* If you need to save or export values you write, combine this block with `CSV Export` or `REST API - Post` to keep external logs or send notifications.

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

* No write happening: check that the `Enable` input is True and that a valid `Modbus Client` is connected.
* Invalid address errors: ensure `Address` is an integer within the device address map and matches the chosen `Data Type`.
* Unexpected data format: for `Coil` use boolean or list of booleans; for `Holding Register` use numbers or a list of numbers.
* Write failures: verify connectivity with `Modbus Read` and confirm the server accepts writes to the target address. Check log messages for details.


---

# 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-write.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.
