# Write Data

The Write Data block writes the data of the remote Modbus Server device to which the selected Modbus Client device is connected.

By default, the block has two input pins:

Input Pin Name | Type | Description
StartingAddress | int32 | The 0-based address of the first IO unit to write.
ValuesToWrite | bool[] / short[] / byte[] (depending on the Data Format). | The values to write to the remote Modbus Server device.

Note: You can also configure the StartingAddress input value as a block property instead of an input pin by right-clicking on the block and selecting the Configure I/O option from the context menu. Note that the Write Data block does not handle double-clicking and has no Edit context menu item.

The Write Data block has the following properties:

Property | Type | Description
Selected Device | IModbusClient | The name of the associated Modbus Client device.
IO Type | WriteableModbusIOType | Specifies the type of the IO units to write (Coils or Holding Registers).
Data Format | ModbusDataFormatType | The data format of the data to write (short array, byte array or Boolean array).
Is Async | Boolean | Determines whether the write operation is performed in a synchronous or asynchronous way. This setting is disabled by default (that is, the write operation is performed synchronously).

This block is executed successfully if the following conditions are met:

- The sum of the StartingAddress and ValuesToWrite values are less than or equal to 65535.
- The value of ValuesToWrite is larger than 1.
- The Selected Device property is configured.
- The IO Type and Data Format properties are configured in one of the below combinations:
  - The IO Type property is set to 16-bit size IO while the Data Format property is set to Short array or Byte array.
  - The IO Type property is set to 1-bit size IO while the Data Format property is set to Boolean array.
- The IO Type property and the ValuesToWrite input value are present in one of the below combinations:
  - The IO Type property is set to 16-bit size IO while the value of the ValuesToWrite input is less than or equal to 1968.
  - The IO Type property is set to 1-bit size IO while the value of the ValuesToWrite input is less than or equal to 123.
- The Modbus Server device responds in time and no network-related errors occur.

If any of the above conditions is not met, the Write Data block generates one of the below exceptions, depending on the type of the error:

Exception | Error
ArgumentOutOfRangeException | The StartingAddress and/or the ValuesToWrite inputs are configured incorrectly.
ArgumentNullException | The ValuesToWrite input is null.
InvalidOperationException | The SelectedDevice property is not set. The IO Type and Data Format properties are configured inconsistently (see the above list for the allowed combinations). A server timeout or other network-related error occured.