# Modbus UA

**URL:** <https://forum.inductiveautomation.com/t/modbus-ua/2159>\
**Category:** Ignition\
**Created:** [August 30, 2010, 6:07pm UTC](https://forum.inductiveautomation.com/t/modbus-ua/2159 "2010-08-30T18:07:39Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [September 15, 2010, 11:37pm UTC](https://forum.inductiveautomation.com/t/modbus-ua/2159/5 "2010-09-15T23:37:50Z")

</div>

Here are some functions you can include in the Global Script Modules section under Project -\> Script Modules. I called the module bit:[code]def getBit(value, position):  
return (value \>\> position) & 1

def setBit(value, position, newValue):  
newValue = (newValue & 1) \<\< position  
mask = 1 \<\< position  
return (value & ~mask) | newValue

def writeBit(tagPath, position, value):  
import system, app  
currentValue = system.tag.getTagValue(tagPath)  
system.tag.writeToTag(tagPath, app.bit.setBit(currentValue, position, value))[/code]To use this script just do the following:`app.bit.writeBit("Path/To/Tag", 0, 1)`The first argument is the tag you want to flip the bit on, the second is the bit position and the third is the value of the bit. Hope this helps.

---

_[View the full topic](https://forum.inductiveautomation.com/t/modbus-ua/2159)._
