Skip to content

Write ​

Purpose: write values to a device's registers or coils.

Write settings

Pick Write in the Add Step window:

FieldWhat it sets
Function05 single coil, 06 single register, 15 multiple coils, 16 multiple registers
FormatValue format (Unsigned, Signed, Long, Float, Double and byte order)
ChannelWhich channel to use (A or B)
Start address / End addressThe range to write. The register count is shown on the right
Max responseResponse time limit, see Common fields
Write valueThe value to write. For several registers it is a table, one value per row

JSON ​

json
{ "write": { "function": 16, "address": "0x0010", "values": [100, 200, 300] } }
FieldRequiredMeaning
addressYesStart address, 0–65535. Expression allowed
end_addressNoEnd address (inclusive). You can use count instead. If neither is given, the number of values decides; otherwise 1
countNoNumber of registers (or coils), 1–123
functionNo5, 6, 15 or 16. If omitted, 06 for one register and 16 for several. 10 is treated as 16
formatNoDefault unsigned. Other formats are in Concepts › 8. Value formats
valueOne of the twoA single value written to every position in the range. Expression allowed
valuesOne of the twoA list of values, one entry each (a float entry takes 2 registers)
channelNo"A" (default) or "B"
max_msNoSee Common fields

Result ​

ResultWhen
PASSThe device accepts the write
FAILThe device returns an exception code (for example, the address does not exist), or the response is slower than max_ms
DISCONNECTThe device does not respond

A Write PASS only means the device accepted the write, not that the value is right. To check the value, add a Read after it.

Example ​

CaseWhat it does
FC06 one registerFC06 writes 0x0000 = 0x1234, then reads it back
FC16 several registersFC16 writes 0x0010..0x0012 = 100, 200, 300, then reads them back
FC05 one coilFC05 turns coil 0x0000 ON, read back with FC01
FC15 several coilsFC15 writes 4 coils 1, 0, 1, 1, read back with FC01
Format and expressionsWrites 12.5 as float_abcd, then uses variable i = 3 to compute the address 0x0030 + ${i} and the value ${i} * 100

Write example result

All five cases PASS. In the last case, the Actual column shows [@0x0033], the address the expression worked out to.

Notes ​

  • Coil values are 0 (OFF) or 1 (ON).
  • Formats other than Unsigned only work with FC16, or with FC06 for single-register formats (such as Signed). They cannot be used with coils.
  • Write cannot store a variable (store is not accepted).

Download the sample script ​

Sample script

Before running it, start a Slave window on 127.0.0.1:502 and click Listen, then open the script with Open JSON in Script mode and click Run. See How to use the examples.

Roach Modbus Tool by Mr.Roach