# Modbus write bit to holding register

**URL:** <https://forum.inductiveautomation.com/t/modbus-write-bit-to-holding-register/3359>\
**Category:** Ignition\
**Created:** [September 28, 2011, 6:31pm UTC](https://forum.inductiveautomation.com/t/modbus-write-bit-to-holding-register/3359 "2011-09-28T18:31:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jay](https://avatars.discourse-cdn.com/v4/letter/j/ed8c4c/32.png) [@jay](https://forum.inductiveautomation.com/u/jay)\
**Post date:** [September 28, 2011, 6:31pm UTC](https://forum.inductiveautomation.com/t/modbus-write-bit-to-holding-register/3359/1 "2011-09-28T18:31:11Z")

</div>

The correct way to set or clear a bit in a holding register is to use Modbus function code 22 (16 hex). Ignition’s Modbus V2 OPC-UA driver supports that. The problem is that very few Modbus slaves support this function code. Even Schneider/Modicon’s M340 and Control Microsystems SCADAPacks don’t support it.

There is certainly a timing problem with setting or clearing a bit in the last read copy of a holding register and then writing it back out using FC 16 or FC 6. But timing problems are all over the place in industrial automation. Where are the block writes to ensure that structured, related data in written at once in anyone’s implementation of OPC? What’s preventing an HMI from clobbering half of a Modbus floating point number? Worse than that, some AB PLCs will update their discrete inputs during a logic scan.

What I’m saying is that the timing problem is not solved in industrial automation, and won’t be, anytime soon. As you continue to work on your Modbus OPC\_UA server, consider that you will do no additional harm by supporting bit writes to registers using FC 16 or FC 6, and make me, at least, a happier camper.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 28, 2011, 6:37pm UTC](https://forum.inductiveautomation.com/t/modbus-write-bit-to-holding-register/3359/2 "2011-09-28T18:37:49Z")

</div>

If you’re aware and OK with the fact that a timing issue exists then you can create a global scripting function that does a read/mask/write and use it on any driver.

I’m not really comfortable with introducing a timing issue that isn’t explicitly invoked and obvious to the user, but you’re right that other timing issues are a reality. Maybe if I implemented this it would be as an option that you had to explicitly enable?

---

<div class="post-metadata">

**Author:** ![nathan](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@nathan](https://forum.inductiveautomation.com/u/nathan)\
**Post date:** [September 28, 2011, 6:48pm UTC](https://forum.inductiveautomation.com/t/modbus-write-bit-to-holding-register/3359/3 "2011-09-28T18:48:18Z")

</div>

@jay and kevin,

What is being asked in this feature request?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 28, 2011, 6:50pm UTC](https://forum.inductiveautomation.com/t/modbus-write-bit-to-holding-register/3359/4 "2011-09-28T18:50:30Z")

</div>

Support for writing to a bit on Modbus devices that don’t support the MaskWriteRegister function.

Essentially, a non-atomic, two request operation: Read the value of the register (1st request), turn a bit on or off, then write the value back to the register (2nd request).

The tricky thing is that you’re not guaranteed that nobody touched the register after you read it, meaning your write could very likely clobber the value that it changed to.

---

<div class="post-metadata">

**Author:** ![jay](https://avatars.discourse-cdn.com/v4/letter/j/ed8c4c/32.png) [@jay](https://forum.inductiveautomation.com/u/jay)\
**Post date:** [September 29, 2011, 5:45pm UTC](https://forum.inductiveautomation.com/t/modbus-write-bit-to-holding-register/3359/5 "2011-09-29T17:45:41Z")

</div>

Yes, Kevin. Putting a check box under the advanced section of the OPC-UA device configuration page that said “use FC 6 for bit masked writes” would do the trick. It would save me and probably other integrators from a lot of busy work and possible errors.

Thanks.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 29, 2011, 5:53pm UTC](https://forum.inductiveautomation.com/t/modbus-write-bit-to-holding-register/3359/6 "2011-09-29T17:53:16Z")

</div>

Or introduce new, subtle, undetectable errors… depends how you want to look at it. 😈

Once the dust from 7.3 settles I’ll see about adding this.

---

<div class="post-metadata">

**Author:** ![anas](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@anas](https://forum.inductiveautomation.com/u/anas)\
**Post date:** [March 31, 2026, 11:54am UTC](https://forum.inductiveautomation.com/t/modbus-write-bit-to-holding-register/3359/7 "2026-03-31T11:54:40Z")

</div>

Hello,

I agree with Jay on this matter, as I am currently facing the same issue with Schneider Modicon devices that do not support Modbus function code 22.

Other SCADA implementations handle this by using FC16/FC6 writes directly to the register. While I understand this approach may introduce timing issues, as mentioned previously in this discussion, I strongly recommend providing an option to enable or disable this behavior within the advanced Modbus driver settings.

I also have another request regarding the Modbus driver. Currently, there is an option in the driver properties:

- Force Multiple Register Writes

However, there is no equivalent option for coils, such as:

- Force Multiple Coil Writes (FC15)

This feature would be very useful, as some PLCs—such as the Modicon M251—do not support FC5 (Single Coil Write) but do support FC15 (Multiple Coil Write).

Thanks
