# Modbus Holding Register Bit Read/Write

**URL:** <https://forum.inductiveautomation.com/t/modbus-holding-register-bit-read-write/6756>\
**Category:** Ignition\
**Created:** [June 24, 2013, 5:32pm UTC](https://forum.inductiveautomation.com/t/modbus-holding-register-bit-read-write/6756 "2013-06-24T17:32:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![allenr8](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@allenr8](https://forum.inductiveautomation.com/u/allenr8)\
**Post date:** [June 24, 2013, 5:32pm UTC](https://forum.inductiveautomation.com/t/modbus-holding-register-bit-read-write/6756/1 "2013-06-24T17:32:32Z")

</div>

I’m trying to read/write the bits out of holding register with the following format:

[PLC]1.40581.1

I get errors of “Bad Quality”. Is there something I am missing? Is the bit level read not supported in Ignition?

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:** [June 24, 2013, 5:51pm UTC](https://forum.inductiveautomation.com/t/modbus-holding-register-bit-read-write/6756/2 "2013-06-24T17:51:16Z")

</div>

Well, ‘40581’ isn’t a valid address, unless you’ve set up a mapping that happens to have a ‘40’ prefix…

---

<div class="post-metadata">

**Author:** ![allenr8](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@allenr8](https://forum.inductiveautomation.com/u/allenr8)\
**Post date:** [June 24, 2013, 6:01pm UTC](https://forum.inductiveautomation.com/t/modbus-holding-register-bit-read-write/6756/3 "2013-06-24T18:01:03Z")

</div>

I did - I read the bit just fine - can’t write.

---

<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:** [June 24, 2013, 6:21pm UTC](https://forum.inductiveautomation.com/t/modbus-holding-register-bit-read-write/6756/4 "2013-06-24T18:21:11Z")

</div>

The ability to write to the bit is entirely dependent on whether the device you’re talking to supports the Mask Writer Register (0x16) function code.

There’s probably an error message in your gateway console about the function not being supported, or if you’re less lucky, the device simply doesn’t respond and you have a message about a request timing out.

---

<div class="post-metadata">

**Author:** ![allenr8](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@allenr8](https://forum.inductiveautomation.com/u/allenr8)\
**Post date:** [June 24, 2013, 6:23pm UTC](https://forum.inductiveautomation.com/t/modbus-holding-register-bit-read-write/6756/5 "2013-06-24T18:23:18Z")

</div>

Would illegal function be a pretty good indication that it is not supported?

---

<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:** [June 24, 2013, 7:50pm UTC](https://forum.inductiveautomation.com/t/modbus-holding-register-bit-read-write/6756/6 "2013-06-24T19:50:00Z")

</div>

A very good indication, yes 🙂

As a work-around you can make a writeBit() scripting function and put it in an app.\* module for re-use.

This may be a good place to start:  
[viewtopic.php?f=71&t=5556&p=32760&hilit=writeBit#p32760](http://inductiveautomation.com/forum/viewtopic.php?f=71&t=5556&p=32760&hilit=writeBit#p32760)

---

<div class="post-metadata">

**Author:** ![Nate.Olson](https://avatars.discourse-cdn.com/v4/letter/n/35a633/32.png) [@Nate.Olson](https://forum.inductiveautomation.com/u/Nate.Olson)\
**Post date:** [September 12, 2016, 7:12pm UTC](https://forum.inductiveautomation.com/t/modbus-holding-register-bit-read-write/6756/7 "2016-09-12T19:12:50Z")

</div>

Hi Kevin,

This thread describes a problem I am currently experiencing. Since the last post is over 3 years old I’m wondering if there are any updated solutions or if I should go the scripting route you described in the previous post? We are on version 7.8.3.

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 12, 2016, 7:22pm UTC](https://forum.inductiveautomation.com/t/modbus-holding-register-bit-read-write/6756/8 "2016-09-12T19:22:56Z")

</div>

[quote=“Nate.Olson”]Hi Kevin,

This thread describes a problem I am currently experiencing. Since the last post is over 3 years old I’m wondering if there are any updated solutions or if I should go the scripting route you described in the previous post? We are on version 7.8.3.

Thanks[/quote]

Yes, if you’re certain the device does not support function code 0x16 (MaskedWriteRegister) then you need to do it via scripting.

---

<div class="post-metadata">

**Author:** ![Nate.Olson](https://avatars.discourse-cdn.com/v4/letter/n/35a633/32.png) [@Nate.Olson](https://forum.inductiveautomation.com/u/Nate.Olson)\
**Post date:** [September 28, 2016, 5:17pm UTC](https://forum.inductiveautomation.com/t/modbus-holding-register-bit-read-write/6756/9 "2016-09-28T17:17:36Z")

</div>

Kevin,

I was able to find some documentation that does indicate the device supports function code 0x16 (see attachment). I also included the error I am seeing in the console. And for a little more information I attached a conversation from Moxa tech support. We are using the device to go TCP to the PLC.

I’m wondering if there are some additional diagnostics or configuration options you could point me to in Ignition?

Another thing that is strange is we are using a different product on the serial side of the Moxa and that is writing to the same point using function code 0x6. I’m wondering why that is using a different code?

Thanks,  
Nate

---

<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, 2016, 5:23pm UTC](https://forum.inductiveautomation.com/t/modbus-holding-register-bit-read-write/6756/10 "2016-09-28T17:23:21Z")

</div>

MaskWriteRegister (0x16) is the only function code you can use to safely write to a bit within a register.

0x06 is WriteSingleRegister. If the other software is writing to a bit using this code it’s doing it by reading the current value, twiddling the bit in question, then writing that new value back down, which is obviously a non-atomic and non-safe operation.

Our driver won’t do this for you, but you can do the same thing yourself in scripting (there’s a couple threads on this topic).

I couldn’t say with any certainty whether your device or the Moxa is the one that doesn’t support function 0x16, but there’s not really any room to dispute or otherwise diagnose that response on the Ignition side.
