# Writing a bit, integer tag

**URL:** <https://forum.inductiveautomation.com/t/writing-a-bit-integer-tag/24409>\
**Category:** Ignition\
**Created:** [April 25, 2019, 8:38pm UTC](https://forum.inductiveautomation.com/t/writing-a-bit-integer-tag/24409 "2019-04-25T20:38:45Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkylep](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@dkylep](https://forum.inductiveautomation.com/u/dkylep)\
**Post date:** [April 25, 2019, 8:38pm UTC](https://forum.inductiveautomation.com/t/writing-a-bit-integer-tag/24409/1 "2019-04-25T20:38:45Z")

</div>

I’m trying to write to a bit (bit #6) of an integer tag with no luck.

Following this  
[https://www.inductiveuniversity.com/videos/addressing-bits/7.9](https://www.inductiveuniversity.com/videos/addressing-bits/7.9)

I copied my tag int\_read1 (copy became int\_read2), changed the OPC Item path to int\_read1.5.  
I can read the bit by writing to int\_read1  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/92e82d683b9360bffb6175dd10ea48e204d9af05.png)

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/76bd906345b985caca36f9c813c5817075f4547e.png)

but if I try to write to it I get an error.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/678ba986760ce09f0d529559eb70a7cb6f01bef8.png)

I’m using 8.0.0 (b2019040718).  
Full read/write gateway communications are allowed.  
The tag has Read/Write access writes.

What am I missing?  
Thanks

---

<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:** [April 25, 2019, 8:50pm UTC](https://forum.inductiveautomation.com/t/writing-a-bit-integer-tag/24409/2 "2019-04-25T20:50:37Z")

</div>

Are you getting that error when toggling the checkbox right in the tag browser? Or just in a piece of code?

---

<div class="post-metadata">

**Author:** ![dkylep](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@dkylep](https://forum.inductiveautomation.com/u/dkylep)\
**Post date:** [April 25, 2019, 8:52pm UTC](https://forum.inductiveautomation.com/t/writing-a-bit-integer-tag/24409/3 "2019-04-25T20:52:32Z")

</div>

Error occurs when toggling the checkbox in tag browser.

---

<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:** [April 25, 2019, 8:58pm UTC](https://forum.inductiveautomation.com/t/writing-a-bit-integer-tag/24409/4 "2019-04-25T20:58:40Z")

</div>

What OPC Server / Driver is this tag coming from?

---

<div class="post-metadata">

**Author:** ![dkylep](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@dkylep](https://forum.inductiveautomation.com/u/dkylep)\
**Post date:** [April 25, 2019, 9:08pm UTC](https://forum.inductiveautomation.com/t/writing-a-bit-integer-tag/24409/5 "2019-04-25T21:08:51Z")

</div>

I’m using the Modbus TCP driver  
Ignition OPC-UA Server

I’m using Productivity 2000 PLCs from Automation Direct

---

<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:** [April 25, 2019, 9:10pm UTC](https://forum.inductiveautomation.com/t/writing-a-bit-integer-tag/24409/6 "2019-04-25T21:10:15Z")

</div>

Check the gateway logs for errors.

Your device probably doesn’t support the MaskWriteRegister request, which is required for writing to individual bits within a word.

---

<div class="post-metadata">

**Author:** ![dkylep](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@dkylep](https://forum.inductiveautomation.com/u/dkylep)\
**Post date:** [April 25, 2019, 9:13pm UTC](https://forum.inductiveautomation.com/t/writing-a-bit-integer-tag/24409/7 "2019-04-25T21:13:14Z")

</div>

You mean something like this…

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/d52e742d8ad76ec310a15e8d767ffb38adb87bd3.png)

That stinks!!

---

<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:** [April 25, 2019, 9:21pm UTC](https://forum.inductiveautomation.com/t/writing-a-bit-integer-tag/24409/8 "2019-04-25T21:21:46Z")

</div>

In spite of that, I happen to be a fan of those processors… they have built-in support for [Ethernet/IP I/O devices](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-ethernetip-class-1-communications), as both scanner and adapter. And my I/O driver **does** have support for bit-level reads and writes within its buffers. (-:

---

<div class="post-metadata">

**Author:** ![dkylep](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@dkylep](https://forum.inductiveautomation.com/u/dkylep)\
**Post date:** [May 2, 2019, 3:22pm UTC](https://forum.inductiveautomation.com/t/writing-a-bit-integer-tag/24409/9 "2019-05-02T15:22:21Z")

</div>

So it turns out the P2K line of PLCs does not accept the ‘MaskWriteRegisterRequest’ from the driver as Kevin had guessed.

In case anyone else is trying to do the same, this is the sudo script I wrote to accomplish flipping a single bit to a 1.

```auto
	currentTag = system.tag.readBlocking(["Path/to/tag"])
	setBit = 8 #Bit position to set
	newValue = 1 << setBit #set bit in correct position
	system.tag.writeAsync(["Path/to/tag"],[newValue | currentTag[0].value]) # OR new value to current tag value

```

---

<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:** [May 2, 2019, 3:26pm UTC](https://forum.inductiveautomation.com/t/writing-a-bit-integer-tag/24409/10 "2019-05-02T15:26:21Z")

</div>

Just be careful and aware of the race condition - if some other process writes to the value, or the PLC changes the value, in between your read and write you’ll clobber that value.

---

<div class="post-metadata">

**Author:** ![leo\_amm](https://avatars.discourse-cdn.com/v4/letter/l/9d8465/32.png) [@leo\_amm](https://forum.inductiveautomation.com/u/leo_amm)\
**Post date:** [May 24, 2019, 10:23am UTC](https://forum.inductiveautomation.com/t/writing-a-bit-integer-tag/24409/11 "2019-05-24T10:23:06Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/e/eb86b4ca82e74bf043fedf444839b0240b73d3df.png)

I’m writing to HR100.Bit from Ignition but it returns the illegal function code error in gateway log.  
From PLC document, it supports the function code x16.

Any idea how to fix this?

---

<div class="post-metadata">

**Author:** ![dkylep](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@dkylep](https://forum.inductiveautomation.com/u/dkylep)\
**Post date:** [May 24, 2019, 12:39pm UTC](https://forum.inductiveautomation.com/t/writing-a-bit-integer-tag/24409/12 "2019-05-24T12:39:07Z")

</div>

If I’m not mistaken. My memory is that the you need the PLC to support the ‘Mask Write Register’ function which I believe is function code 22.

I think function code 16 is for write multiple.

---

<div class="post-metadata">

**Author:** ![leo\_amm](https://avatars.discourse-cdn.com/v4/letter/l/9d8465/32.png) [@leo\_amm](https://forum.inductiveautomation.com/u/leo_amm)\
**Post date:** [May 27, 2019, 2:44am UTC](https://forum.inductiveautomation.com/t/writing-a-bit-integer-tag/24409/13 "2019-05-27T02:44:19Z")

</div>

Thank you. Seems, I have to go with the script to do this. 😃
