# Reading and Writing to Multiple Bits on a Register

**URL:** <https://forum.inductiveautomation.com/t/reading-and-writing-to-multiple-bits-on-a-register/77605>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [August 9, 2023, 1:56am UTC](https://forum.inductiveautomation.com/t/reading-and-writing-to-multiple-bits-on-a-register/77605 "2023-08-09T01:56:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![IcedMocha12](https://avatars.discourse-cdn.com/v4/letter/i/82dd89/32.png) [@IcedMocha12](https://forum.inductiveautomation.com/u/IcedMocha12)\
**Post date:** [August 9, 2023, 1:56am UTC](https://forum.inductiveautomation.com/t/reading-and-writing-to-multiple-bits-on-a-register/77605/1 "2023-08-09T01:56:25Z")

</div>

Hi All,

I was wondering if there was a way to read grouped bits from a register. One of the devices I'm reading/writing from has registers that require you to read and write to grouped bits for different functions.

For example:  
[Device\_1]HRUS108 gives you an operating status at Bit 2 and Bit 3. 0=off, 1=,on, 3= fault, 4 = Error.  
On the same device, Bit 14 and Bit 15 would be something like 0=Error, 1=Disconnected, 2 = Connected, 3= Alarm.

So there's a bunch of data shoved into one register. Different Registers require me to write to grouped bits as well, some of them spanning 3 total bits instead of 2 like the above example.

Here's another example of a sample register:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/e/ce1baec4a4b839559b0b952b1591272f10cc32b5.png)

Bit 8 and 9 you could write to, however I'm unsure how to write to the grouped bits0-2 and bits10-15  
Is this possible to do?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 9, 2023, 11:43am UTC](https://forum.inductiveautomation.com/t/reading-and-writing-to-multiple-bits-on-a-register/77605/2 "2023-08-09T11:43:12Z")

</div>

You would have to convert the bit fields to groups of booleans, and write the booleans in a single operation (single list for `system.tag.writeBlocking()` or `system.opc.writeValues()`). Do note that it won't work at all if the device doesn't implement the modbus function code for masked writes to holding registers (Schneider is notorious for this).

FWIW, my [alternate Modbus driver](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-advanced-modbus) does implement bit fields in this fashion for you, so you get an unsigned integer to work with.

---

<div class="post-metadata">

**Author:** ![IcedMocha12](https://avatars.discourse-cdn.com/v4/letter/i/82dd89/32.png) [@IcedMocha12](https://forum.inductiveautomation.com/u/IcedMocha12)\
**Post date:** [August 9, 2023, 3:15pm UTC](https://forum.inductiveautomation.com/t/reading-and-writing-to-multiple-bits-on-a-register/77605/3 "2023-08-09T15:15:14Z")

</div>

How would you group the booleans in the bitfield? I could only find a resource where you can read individual bits of the register.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 9, 2023, 3:24pm UTC](https://forum.inductiveautomation.com/t/reading-and-writing-to-multiple-bits-on-a-register/77605/4 "2023-08-09T15:24:58Z")

</div>

When reading, just read the whole register and apply bitwise logical AND and a shift to get just the field.
