IMDTouchKnowledge BaseShop main store

Troubleshooting

Why a Modbus TCP write clears in the PLC input area

HMI and touchscreens Published 7 min read By IMDTouch engineering team

Short answer

The panel write succeeds: the holding register it lands in is mapped into the controller's input area, and the cyclic input-image refresh overwrites that word every task cycle, so the value appears briefly and returns to zero. Configure the holding registers to overlay the slave's output area so the application owns them, and test zero separately, because a nonzero-only copy in the program only masks the fault.

On this page
  1. Why does the panel write land and then clear to zero?
  2. Which register does the write actually reach?
  3. Why does the input image overwrite the mapped %IW variable?
  4. How do you remap the holding registers to a variable the program owns?
  5. Why can't you fix it with a nonzero-only copy?
  6. How do you test the fix without a false pass?
  7. When is the clearing not this input-image problem?
  8. Questions asked

Your panel write is succeeding and then being undone. The holding register it lands in is mapped to the controller's input area, and the cyclic input-image refresh copies the device's process image back over that word every task cycle, so the value appears briefly and returns to zero. The fix is to expose the panel-written registers as variables the application owns — on a CODESYS Modbus TCP slave, by configuring the holding registers to overlay the output area — and then to test zero separately, because a nonzero-only copy in the program hides this fault while blocking legitimate zero commands.

Why does the panel write land and then clear to zero? #

The write is not failing on the network: the function-code-6 request lands in a holding register that the slave maps to the input area, and the controller's cyclic input-image refresh then copies the device buffer back over it, so the value reverts within a task cycle. Everything before that point works. The master sends the request, the slave accepts it, and the mapped %IW word briefly shows the written value. What kills it is a later, local write inside the controller, not a timeout, an addressing offset or a bad checksum. That is also why the symptom is so consistent: the value never survives longer than the refresh interval of the task the slave device belongs to.

Which register does the write actually reach? #

A panel write reaches the slave as a Modbus function code 6 (write single register) request, and the register field in that request selects which holding register the slave device updates. Worked example from a documented FC06 frame: the master addresses slave 17 and register 40002, so the register field carries 40002 − 40001 = 1, and the value field carries the data word — for example 750, which is 0x02EE on the wire. On the default slave mapping, holding register 40001 (register field 0) is the first word the device exposes, which is why writes like yours show up at %IW0. Register-numbering conventions differ between tools, so if the value lands in the wrong word entirely, work through decoding Modbus holding register addresses on the way from PLC to HMI before touching any logic.

Why does the input image overwrite the mapped %IW variable? #

Because a CODESYS Modbus TCP slave exposes its holding registers in the slave's input (%I) area by default, and the runtime refreshes that input image from the device every cycle, so the written word survives only until the next refresh. The documented remedy is the configuration, not the program: the holding registers (slave %I) can be configured to overlay the area backed by %Q, and that overlay is exactly what makes them updatable and retainable by the slave's own application. Until you do that, the value lives in an image the controller owns and rewrites. Your own diagnostic already proved it: with one variable bound to both %IW0 and %QW0, it reads 0, because the input side wins every cycle. The same pattern exists elsewhere — at least one other controller line defines a holding register as input-only in its dynamic channel mode — so treat this as a mapping fault class, not a network one.

How do you remap the holding registers to a variable the program owns? #

Map the holding registers onto the slave's output (%Q) area on the I/O mapping of Modbus_TCP_Slave_Device, keep the read-only data in the input registers, and remove any cyclic assignment that copies another value over the command variable. The address %IW0 is simply the first word of that input image; the page on what CODESYS %IW0 means for a Modbus TCP holding register walks the same mapping in detail. Then work through the configuration in this order:

  1. Open the Modbus_TCP_Slave_Device in the PLC project and go to its I/O Mapping tab, where the register areas are bound to variables.
  2. Leave the input registers mapped to %IW variables that the program writes — this is the data the master reads, the direction the vendor example calls "toMaster".
  3. Configure the holding registers to overlay the slave's %Q-backed area so the application can hold them — the direction the same example calls "fromMaster" — and bind them to the command variables the program actually uses.
  4. Point the panel's writable object at the same holding register address and data format you just mapped.
  5. Search the application for every assignment to those command variables and delete any cyclic copy from another source, including initialization writes.
  6. Download both configurations and monitor the mapped word and the application variable together while writing from the panel.

After step 6 the panel write and the program share one variable, so the value persists until something legitimately changes it.

Why can't you fix it with a nonzero-only copy? #

Because the guard IF var_I <> 0 THEN var_Q:=var_I; END_IF only masks the clearing: it copies genuine values across before the refresh wipes the input word, but it also rejects a legitimate zero, so the panel can change a setpoint and can never reset it. That is not a fix, it is a filter sitting on top of the fault. If you genuinely cannot remap the slave device on this machine, the committed alternative is a handshake: the panel writes the value to the holding register, then writes 1 to a separate trigger register, and the program copies the value — including zero — only while the trigger is set, then clears the trigger. Zero becomes a valid command again because the trigger, not the value, carries the write event. Even so, the overlay mapping is the cleaner solution, and it is the one to choose when you own the PLC project.

How do you test the fix without a false pass? #

Test one nonzero value and one zero from the panel, and watch the application variable through several task cycles after each write — a value that only appears briefly is exactly the symptom you are fixing, so a single glance proves nothing. Run the test in this order:

  1. Put the machine in a state where a persisted setpoint cannot move anything, because after this fix panel writes stick — bench the test or disable the outputs first.
  2. Write a nonzero value from the panel, for example 750, and confirm the request, the mapped holding register and the application variable all show 750.
  3. Keep watching past the refresh interval: on a 10 ms cyclic task the input image refreshes 1000 ms / 10 ms = 100 times per second, so under the old mapping the value died within tens of milliseconds — hold the observation for several seconds to cover it.
  4. Write 0 from the panel and confirm the application variable reads 0 and stays there; this is the case the nonzero-only guard always failed.
  5. Confirm any dependent logic, alarms or outputs respond to both values as intended.

If zero still will not stick after the remap, hunt for a second writer: a minimum-value limit, a first-cycle initialization or another cyclic assignment to the same variable.

When is the clearing not this input-image problem? #

If the value never appears in the expected register at all, or a written coil reverts after exactly one poll cycle, the input-image refresh is not your mechanism: the fault is in register addressing or in a master that rewrites its own copy every poll. Check which pattern you have before changing any PLC logic:

Decide by observing who writes last: if the last writer is the master, fix the panel; if the last writer is the controller's own refresh or program, fix the mapping.

Questions asked

Why did the same panel behave correctly against the previous-generation runtime?

The most likely difference is the slave implementation. Older Modbus TCP slave drivers exposed holding registers directly as writable application variables, so nothing stood between the master's write and the value the program used. The current device maps the write area into the input image by default, which is what introduces the cyclic overwrite.

Should the panel read the written value back from the same register?

Read it back from a separate input register that the application feeds, not from the register you write. A readback from the written holding register only proves the value was stored; a readback from the application variable also shows when the program clamps, scales or refuses the command, which is the number the machine actually runs with.

Does the same clearing happen to input registers?

No, because a master cannot write input registers at all: function code 4 reads them and the write function codes target holding registers and coils. The clearing case is specific to how the slave backs its holding-register area. Input registers matter to you only as the readback path for values the application owns.

Can two operator panels write the same holding register?

They can, but the last write wins with no arbitration, so two stations can silently overwrite each other's setpoints. If more than one panel must issue commands, give each station its own command register with a trigger, and have the program apply them in a defined order. A single writable command register per value is the safer default.

Keep reading

  • Troubleshooting

    Writing WAGO 750 PLC Digital Outputs From a Weintek HMI

    Your read at 0x 513 is already the right address: in the panel's 0x notation it is decimal bit 512, %QX0.0, inside the WAGO physical output area 512–767 (0x0200–0x02FF). The write fails because the CODESYS program assigns %QX0.0 every scan and overwrites it, so command an internal memory bit and let the logic drive the output.

    HMI and touchscreens

  • Troubleshooting

    Why PLC Modbus reads from an HMI stop after five minutes

    A one-directional failure means the link and the write path are healthy and the PLC's read transaction is at fault. Count read attempts separately from read successes, test single 16-bit words at zero-based offsets 0, 1 and 2, then restore the float pairs one range at a time until the frozen branch shows itself.

    HMI and touchscreens

  • Troubleshooting

    Why a CLICK PLC rejects one in three HMI button writes

    Neither EasyBuilder Pro driver is the fault: both tested drivers reproduced the same failure, so individual Modbus TCP writes are going unserved past the HMI timeout while reads and retries succeed. Run a one-button project on the same hardware for 30 presses per driver, then let the failure count decide between fixing the full project's polling load and fixing the link or the PLC's reply time.

    HMI and touchscreens

How to Display Dynamic PLC Messages on a PanelView 800