# Is it possible to use getBit in a UDT?

**URL:** <https://forum.inductiveautomation.com/t/is-it-possible-to-use-getbit-in-a-udt/69910>\
**Category:** Ignition\
**Tags:** ignition79, vision\
**Created:** [February 15, 2023, 7:27pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-use-getbit-in-a-udt/69910 "2023-02-15T19:27:48Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brittany\_Villasenor](https://avatars.discourse-cdn.com/v4/letter/b/e68b1a/32.png) [@Brittany\_Villasenor](https://forum.inductiveautomation.com/u/Brittany_Villasenor)\
**Post date:** [February 15, 2023, 7:27pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-use-getbit-in-a-udt/69910/1 "2023-02-15T19:27:48Z")

</div>

I'm trying to make templates for a Faults Page. Here is an example of one fault in Ignition:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/1/f1fc30e638cd15e84be5408ab026de841804bfa8.png)

The faults start off as this:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/2/2290b1ad765ae1643bb064ee2368b526391a2e2d.png)

And have to be extracted using getBit, like so:  
`getBit({[default]_AR_Merchandising_/Program:Saw_1/HMI_ACC_1/Accumulator_Faults/Accumulator_Faults_0_}, 0)`

The multilight indicator uses getBit to determine if a fault has occurred, and the labels are strongly typed. Is there a way to use getBit in a UDT so I can use templates instead of copying/pasting hundreds of potential faults?

I looked at the Templates videos and there was nothing about getBit in there. Any suggestions or tips greatly appreciated.

---

<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:** [February 15, 2023, 7:33pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-use-getbit-in-a-udt/69910/2 "2023-02-15T19:33:34Z")

</div>

UDTs can contain expression tags, which can use `getBit()` on other members of the UDT. Just use the `{[.]someMember}` tag syntax to reference peer members of the UDT (same folder level), or variations thereof.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 15, 2023, 7:37pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-use-getbit-in-a-udt/69910/3 "2023-02-15T19:37:30Z")

</div>

This may be useful.

> [@Read 16-Bit Modbus Input Register to two 8-Bit tags](https://forum.inductiveautomation.com/t/read-16-bit-modbus-input-register-to-two-8-bit-tags/29614/2):
>
> I had written a UDT for DINT to BIT. Feel free to modify to your needs. [DINT2BIT\_UDT.xml](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/990bf35ca7703ec7d47bcf79abdc40bbbc0b4761.xml) (8.9 KB)

---

<div class="post-metadata">

**Author:** ![Brittany\_Villasenor](https://avatars.discourse-cdn.com/v4/letter/b/e68b1a/32.png) [@Brittany\_Villasenor](https://forum.inductiveautomation.com/u/Brittany_Villasenor)\
**Post date:** [February 16, 2023, 6:15pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-use-getbit-in-a-udt/69910/4 "2023-02-16T18:15:25Z")

</div>

Hey Jordan,

That looks very useful!  
I've adjusted the code but am confused on what this last line is doing:

```auto
 <Tag name="Input Value" path="" type="OPC">
         <Property name="Value"/>
         <Property name="DataType">2</Property>

```

---

<div class="post-metadata">

**Author:** ![Brittany\_Villasenor](https://avatars.discourse-cdn.com/v4/letter/b/e68b1a/32.png) [@Brittany\_Villasenor](https://forum.inductiveautomation.com/u/Brittany_Villasenor)\
**Post date:** [February 16, 2023, 6:37pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-use-getbit-in-a-udt/69910/5 "2023-02-16T18:37:50Z")

</div>

I am very new to Ignition. Would I drag and drop the entire Accumulator Faults folder... or would I drag and drop each Falt Tag? I've tried with the entire folder and set up these parameters:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/2/321d69c897c687113c04562c9343070ac468abe0.png)  
I then tried to add an expression tag like so:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/5/f52e70c36b0800edb981a1509f04a796a67681d4.png)  
Here are the general settings for the Expression tag Bit0:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/4/844ef1657015b5a1da73c505a9234d2b38c4439a.png)

Am I going about this the correct way so far?

---

<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:** [February 16, 2023, 6:58pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-use-getbit-in-a-udt/69910/6 "2023-02-16T18:58:00Z")

</div>

No Parameters for the bits. An OPC tag to bring in the integer. An expression tag adjacent to it for each bit you wish to extract. So your UDT would have 33 tags to extract all of the bits of a 32-bit integer.

---

<div class="post-metadata">

**Author:** ![Brittany\_Villasenor](https://avatars.discourse-cdn.com/v4/letter/b/e68b1a/32.png) [@Brittany\_Villasenor](https://forum.inductiveautomation.com/u/Brittany_Villasenor)\
**Post date:** [February 16, 2023, 9:21pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-use-getbit-in-a-udt/69910/7 "2023-02-16T21:21:36Z")

</div>

Like this?

I brought in my integer OPC tag:

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

And then have started making these expressions tags as NewMembers:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/f/5f946b2bb3bcad119d2d6bd4922d336bb5628724.png)

Really appreciate you walking me through this.

---

<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:** [February 16, 2023, 9:23pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-use-getbit-in-a-udt/69910/8 "2023-02-16T21:23:30Z")

</div>

That first one should be `getBit({[.]Accumulator_Faults_0_}, 0)`

Use tag names in curly brace expressions (or property names). OPC Item path syntax is **only** for use in item paths.

---

<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:** [February 16, 2023, 9:29pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-use-getbit-in-a-udt/69910/9 "2023-02-16T21:29:22Z")

</div>

Side note: Your PLC appears to be Allen-Bradley Logix (or possibly Omron NJ/NX). Direct bit access without using `getBit()` is supported on such processors simply by editing the item path to include a dot and the bit number. Then you don't need a tag for the integer as a whole. Drivers are smart enough to read the integer to get the bits efficiently. You can also **write** to individual bits when they are addressed at the driver level.

If you do this in a UDT, you should make a parameter to hold the OPC item path for the integer, then the OPC item paths for the bits would look like `{someParameter}.0` and `{someParameter}.1` ...

---

<div class="post-metadata">

**Author:** ![Brittany\_Villasenor](https://avatars.discourse-cdn.com/v4/letter/b/e68b1a/32.png) [@Brittany\_Villasenor](https://forum.inductiveautomation.com/u/Brittany_Villasenor)\
**Post date:** [February 16, 2023, 10:19pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-use-getbit-in-a-udt/69910/10 "2023-02-16T22:19:04Z")

</div>

Yes, these are Allen-Bradley Logix PLC's that I am working with. That is great information to have.  
I added the path to the parameters:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/f/9fb7fa30dba22611f6123c3b673bcae4f7bb5374.png)

And then added TEST\_Bit0 like so:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/3/83953301a852ac6f7c18c686bf1b9fb013b1ae9c.png)

Does that look right? I dropped the tag on a control and it seems to be working beautifully.

---

<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:** [February 16, 2023, 10:21pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-use-getbit-in-a-udt/69910/11 "2023-02-16T22:21:29Z")

</div>

Yes, looks good. Consider using a more unique parameter name than `Path`. Simple names like that cause trouble when nesting UDTs inside each other, and there's a parameter name in common.

---

<div class="post-metadata">

**Author:** ![Brittany\_Villasenor](https://avatars.discourse-cdn.com/v4/letter/b/e68b1a/32.png) [@Brittany\_Villasenor](https://forum.inductiveautomation.com/u/Brittany_Villasenor)\
**Post date:** [February 16, 2023, 10:22pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-use-getbit-in-a-udt/69910/12 "2023-02-16T22:22:22Z")

</div>

You are a life saver. And noted on the parameter name... I'll spruce it up a bit so it's not so generic. Thanks again!

---

<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:** [February 16, 2023, 10:24pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-use-getbit-in-a-udt/69910/13 "2023-02-16T22:24:29Z")

</div>

I like to include the UDT's type name in its parameter names so they are sure to be unique. For an example, you might try the JSON that my souped-up new Logix driver produces:

> [@Automation Professionals' EtherNet/IP Communication Suite V2](https://forum.inductiveautomation.com/t/automation-professionals-ethernet-ip-communication-suite-v2/68190):
>
> Automation Professionals is pleased to announce its latest EtherNet/IP Communications Suite driver module, a major upgrade to its EtherNet/IP Class1 Communications module, as a Public Beta. As of April 15, 2023, this is now a Production Release. The primary new feature is its new Generic EtherNet/IP Client Driver, a drop-in replacement for IA's Logix V21+ driver and its Omron NJ/NX driver. It does work with older Logix processors, and also works with Rockwell's MicroLogix 8xx family (ethernet…

---

<div class="post-metadata">

**Author:** ![Brittany\_Villasenor](https://avatars.discourse-cdn.com/v4/letter/b/e68b1a/32.png) [@Brittany\_Villasenor](https://forum.inductiveautomation.com/u/Brittany_Villasenor)\
**Post date:** [February 20, 2023, 9:24pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-use-getbit-in-a-udt/69910/14 "2023-02-20T21:24:37Z")

</div>

Hi! I have a quick question. The second approach you showed me with making the bits from OPC tags, I really like that approach but I'm unsure on how to make this work for a template since there will be more than one Accumulator eventually. I was curious as if it was possible before I begin digging into a solution.

---

<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:** [February 20, 2023, 9:31pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-use-getbit-in-a-udt/69910/15 "2023-02-20T21:31:27Z")

</div>

Name your bits by function, not by position in the word. Make your templates reference tags by indirectly combining outer tagpath with a bit's name.
