Easy Modbus Register maps →

How do I write to a Modbus register safely, and put it back afterwards?

Updated 10 November 2026

Short answer

Use function code 06 to write one holding register, 16 to write several (a 32-bit value needs two, so it is always 16), and 05 to switch a single coil. Before writing, read the register and write down what it says. Convert the value you want into raw register contents using the register's scale and word order — a setpoint of 72.5 kept in tenths is written as 725. Afterwards, read it back. Modbus has no priority levels, no release and no timeout: whatever you write simply is the value until something overwrites it, so writing the original value back by hand is the only undo you get.

Why writing to Modbus deserves more care than BACnet

BACnet keeps a priority array: your override sits in a slot, and releasing the slot hands control back. Modbus has nothing of the kind. A holding register is a box with a number in it. Write 55 and it contains 55, full stop, until the equipment's own logic or another system writes something else — and many devices' logic never will. Read is it safe to write to a Modbus register? before touching anything on live plant.

Step 1 — Read it and write down what it says

Read the register first, from the right table at the right address, and note the value and the time. That note is your way back. If the map has a configuration section — unit ID, baud rate, parity — leave those addresses alone unless that is the job: a wrong write there can make the device stop answering.

Step 2 — Work out the raw value

A register holds a raw 16-bit number, not the engineering value you see on a display. Before writing, turn the value you want into what the register actually stores:

Step 3 — Write with the right function code

What you are writingFunction code
One coil (on/off)05 — write single coil
Several coils15 — write multiple coils
One 16-bit holding register06 — write single register
Several registers, or any 32-bit value16 — write multiple registers

Some devices accept only 16, even for a single register; if 06 comes back with an illegal function exception, try 16 with a count of one. See Modbus function codes explained.

Step 4 — Read it back

A successful reply only means the device accepted the request. Read the register again: what it holds now is the truth, not what you asked for. A device can clamp a value to its own limits, round it, or have its control logic overwrite it a second later — all things you only see by reading back.

Step 5 — Put it back

When the test is over, write the value you noted in step 1. It is not a true undo — if the equipment's own logic changed the register in between, "back" means back to what you found, not to what would be there had you never visited — but it is the closest Modbus allows.

If you overrode something to prove a point, put it back before you leave site. Nobody else can see that you did it, and nothing will time it out.

Registers you cannot write