Is it possible to use getBit in a UDT?

I'm trying to make templates for a Faults Page. Here is an example of one fault in Ignition:

The faults start off as this:

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.

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.

This may be useful.

Hey Jordan,

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

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

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:

I then tried to add an expression tag like so:

Here are the general settings for the Expression tag Bit0:

Am I going about this the correct way so far?

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.

Like this?

I brought in my integer OPC tag:

And then have started making these expressions tags as NewMembers:

Really appreciate you walking me through this.

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.

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 ...

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:

And then added TEST_Bit0 like so:

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

1 Like

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.

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!

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:

1 Like

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.

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.

1 Like