Next
ReferenceHardwareModbusWrite task

Modbus write task

Write command channel values to the coils and holding registers of a Modbus server.

A Modbus write task writes the values of command channels to the coils and holding registers of one Modbus server. For example, a button on a schematic can start a pump through a coil of a PLC. Modbus write tasks have no state channels.

Each command writes only the addresses of the channels in the command. Channels at adjacent addresses go in one request. The Driver writes coils with function code 15 and holding registers with function code 16. For a device that supports only function codes 05 and 06, set Write codes of the server to Single. The Driver then writes each register on its own, so the two halves of a 32-bit value can reach the device at different times. A write goes before reads that wait for the same connection.

To write one bit of a holding register, the Driver reads the register, changes the bit, and writes the register back. If the device changes another bit of the register between the read and the write, the write removes that change. For a device that supports function code 22, select Mask write (FC22) on the server. The Driver then changes the bit with one request, and the other bits stay as the device has them.

Before you start, you need a connected server.

Create a Modbus write task

When you create command channels with a client library, give each one its own index channel. A writer that holds several commands on one index must write all of them in every frame.

Enterprise
  1. In the devices toolbar, right-click the server and select Create write task.
  2. Click Add channel. Select the type, then enter the address. For a holding register, select the Data type. For a holding register bit, enter the Bit.
  3. Click (Start).

The Console creates a command channel and an index channel for each output. For the server Pump skid PLC, a coil at address 3 gives Pump_skid_PLC_coil_output_3_cmd and Pump_skid_PLC_coil_output_3_cmd_time. To use a different name, right-click the channel and select Rename before you start the task.

The task has the options Data saving and Auto start. See task options. Python WriteTask has no data_saving_disabled argument.

Channel reference

Each channel has an address, from 0 to 65535, and a channel, the command channel. Each table shows the Console label of a setting, with its Python field under it.

The Console also accepts a six-digit Modicon address, such as 400001 for holding register 0. The first digit is the table: 0 for coils and 4 for holding registers. The Console shows the Modicon form next to each address.

Coil

Python CoilWriteChannelTypeScript coil

Writes a coil. A command of 0 turns the coil off. Any other value turns it on.

Troubleshooting

“Illegal function”

The device does not support function code 15 or 16. Set Write codes of the server to Single.

The connection dropped

The Driver reconnects and sends the command again at once, up to the Retries of the server. If that fails, the task shows the warning “Failed to write commands” and keeps running. The Driver reconnects at the next command.

For other problems, see Connect a Modbus server and Troubleshoot hardware.