# Modbus Write

This function block is used to write data to a Modbus server, facilitating communication between devices in automation systems. It allows the user to specify the address and type of data to be written.

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

`Enable` A boolean input that activates or deactivates the Modbus write operation.

`Modbus Client` This input connects to the Modbus client used for communication with the server.

`Data` The actual data or value to be written to the specified address on the Modbus server.

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

This function block does not produce any outputs.

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

`Address` A field to specify the Modbus address where the data will be written.

`Data Type` A dropdown menu that allows the user to select the type of data being written, either `Coil` or `Holding Register`.

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

`Dynamic Data Writing` Users can specify which address and data type to write to in real-time.

`Error Logging` The block automatically logs errors encountered during the write process, aiding in troubleshooting.

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

1. **Enable the Operation**: Ensure the `Enable` input is set to `True`.
2. **Specify Address**: Enter the Modbus address in the `Address` input field where you want to write the data.
3. **Select Data Type**: Choose the appropriate data type (either `Coil` or `Holding Register`) from the `Data Type` dropdown.
4. **Provide Data**: Connect the desired data to the `Data` input.
5. **Execute the Write**: The write operation will be triggered automatically when the inputs are configured and the block is evaluated.

## 📊 Evaluation <a href="#evaluation" id="evaluation"></a>

Upon execution, the block will write the specified data to the Modbus server at the defined address and log any errors that occur during the process.

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

<details>

<summary>Verifying Modbus Connection</summary>

Before writing data, ensure that the Modbus client is properly initialized and connected. You can use a dedicated Modbus monitoring tool to check the connectivity.

</details>

<details>

<summary>Handling Different Data Types</summary>

When writing multiple values for `Coil` or `Holding Register`, ensure that the data is supplied as a list. If you're writing a single value, ensure it is the correct format that matches the data type being written.

</details>

<details>

<summary>Testing Write Operations</summary>

Always test with known addresses and values in a controlled environment to confirm the write operations succeed before deploying to a live system.

</details>

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

<details>

<summary>Data Not Writing</summary>

If data is not being written, check the following:

* Ensure the `Enable` input is set to `True`.
* Verify the address is valid and within the correct range for the selected data type.
* Confirm the Modbus client is connected and functioning correctly.

</details>

<details>

<summary>Error Messages</summary>

If you encounter an error message while writing, refer to the log for specific details. Address common errors such as address range issues or unsupported data types according to the Modbus protocol you are using.

</details>
