# Derived tag, multiple bit to modbus tag

**URL:** <https://forum.inductiveautomation.com/t/derived-tag-multiple-bit-to-modbus-tag/34871>\
**Category:** Ignition\
**Created:** [May 19, 2020, 7:19am UTC](https://forum.inductiveautomation.com/t/derived-tag-multiple-bit-to-modbus-tag/34871 "2020-05-19T07:19:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![SBL\_MC](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sbl_mc/32/56813_2.png) [@SBL\_MC](https://forum.inductiveautomation.com/u/SBL_MC)\
**Post date:** [May 19, 2020, 7:19am UTC](https://forum.inductiveautomation.com/t/derived-tag-multiple-bit-to-modbus-tag/34871/1 "2020-05-19T07:19:37Z")

</div>

Hi all,

Need some advice on how to solve this. We use derived tags to set and reset bits in a modbus int, command word. This works as long as we do bit by bit. But… I got some buttons that is intended to alter 3 bits at once. It seems that we run into some timing issues, as only the last instruction is done.

I have tried both system.tag.write and system.tag.writeAll on my 3 derived tags.

Button 1  
Set bit 10  
Res bit 11  
Res bit 12

Button 2  
Res bit 10  
Set bit 11  
Res bit 12

Button 3  
Res bit 10  
Res bit 11  
Set bit 12

Example derived tag:

Read expression:  
getBit(toInt({source}),12)

Write expression:  
if({value},  
toInt({source}) | (1 \<\< 12),  
toInt({source}) & ~(1 \<\< 12))

IGN 8.0.9

Thanks in advance.

---

<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 19, 2020, 12:55pm UTC](https://forum.inductiveautomation.com/t/derived-tag-multiple-bit-to-modbus-tag/34871/2 "2020-05-19T12:55:33Z")

</div>

Enable the “Optimistic Writes” option for the tag group these tags belong to.

---

<div class="post-metadata">

**Author:** ![SBL\_MC](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sbl_mc/32/56813_2.png) [@SBL\_MC](https://forum.inductiveautomation.com/u/SBL_MC)\
**Post date:** [May 19, 2020, 1:15pm UTC](https://forum.inductiveautomation.com/t/derived-tag-multiple-bit-to-modbus-tag/34871/3 "2020-05-19T13:15:59Z")

</div>

Hi Kevin,

We tried this with no luck.

---

<div class="post-metadata">

**Author:** ![SBL\_MC](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sbl_mc/32/56813_2.png) [@SBL\_MC](https://forum.inductiveautomation.com/u/SBL_MC)\
**Post date:** [May 25, 2020, 10:45am UTC](https://forum.inductiveautomation.com/t/derived-tag-multiple-bit-to-modbus-tag/34871/4 "2020-05-25T10:45:40Z")

</div>

Hi Kevin,

Restored the gateway on our test server and connected to a PLC on my desk.

Enabling optimistic write does nothing, first when we change optimistic write timeout from 0 to 3000 we see a difference. It works better, meaning two or more bit is not high at the same time - but the first press will most times only disable bits. It will require a second or more click to enable the bit we would like to set.

3 buttons, 3 bits that needs to be altered. All of them belong in a UDT. Tried to add derived tags without a UDT but still the same.

Script, event:

> system.tag.write("[TKV\_TagProvider]D52\_HFS\_Kjoling/HFS/OBJ/Kommando/Pri P2",False)  
> system.tag.write("[TKV\_TagProvider]D52\_HFS\_Kjoling/HFS/OBJ/Kommando/Pri Alt",False)  
> system.tag.write("[TKV\_TagProvider]D52\_HFS\_Kjoling/HFS/OBJ/Kommando/Pri P1",True)

---

<div class="post-metadata">

**Author:** ![SBL\_MC](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sbl_mc/32/56813_2.png) [@SBL\_MC](https://forum.inductiveautomation.com/u/SBL_MC)\
**Post date:** [May 25, 2020, 10:50am UTC](https://forum.inductiveautomation.com/t/derived-tag-multiple-bit-to-modbus-tag/34871/5 "2020-05-25T10:50:14Z")

</div>

Also tried writeAll, still the same.

---

<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 25, 2020, 12:57pm UTC](https://forum.inductiveautomation.com/t/derived-tag-multiple-bit-to-modbus-tag/34871/6 "2020-05-25T12:57:26Z")

</div>

It works for me when using writeBlocking:

```auto
tags = [
"[default]IntBits_Instance/Bit0",
"[default]IntBits_Instance/Bit1",
"[default]IntBits_Instance/Bit2",
"[default]IntBits_Instance/Bit3"
]

values = [1,1,1,1]

system.tag.writeBlocking(tags, values)

```

or

```auto
system.tag.writeBlocking(["[default]IntBits_Instance/Bit0"], [1])
system.tag.writeBlocking(["[default]IntBits_Instance/Bit1"], [1])
system.tag.writeBlocking(["[default]IntBits_Instance/Bit2"], [1])
system.tag.writeBlocking(["[default]IntBits_Instance/Bit3"], [1])

```

It didn’t work with individual async writes, though, and I’m not sure if that’s correct behavior or not. I’ll have to open a ticket and get someone to look into it this week.

---

<div class="post-metadata">

**Author:** ![SBL\_MC](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sbl_mc/32/56813_2.png) [@SBL\_MC](https://forum.inductiveautomation.com/u/SBL_MC)\
**Post date:** [May 25, 2020, 1:50pm UTC](https://forum.inductiveautomation.com/t/derived-tag-multiple-bit-to-modbus-tag/34871/7 "2020-05-25T13:50:14Z")

</div>

Hi Kevin, thanks for writing back.

I tried using writeBlocking now. Its maybe a bit improved. I had to swap about 8-9 times before it failed again. My command word is set to zero.

Looking forward to what the ticket brings. Have a nice day.

---

<div class="post-metadata">

**Author:** ![SBL\_MC](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sbl_mc/32/56813_2.png) [@SBL\_MC](https://forum.inductiveautomation.com/u/SBL_MC)\
**Post date:** [June 4, 2020, 10:32am UTC](https://forum.inductiveautomation.com/t/derived-tag-multiple-bit-to-modbus-tag/34871/8 "2020-06-04T10:32:12Z")

</div>

Hi Kevin,

Do you have any news for us? 🙂

---

<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 4, 2020, 2:54pm UTC](https://forum.inductiveautomation.com/t/derived-tag-multiple-bit-to-modbus-tag/34871/9 "2020-06-04T14:54:42Z")

</div>

Sorry, this fell off my radar. I just wrote up a ticket so it won’t get forgotten.
