HOA Switch With Bits

I am integrating an old PLC-5 into an existing Ignition project.

The plc program has hand, off and auto control as individual bits. For my other application I used a UDT that has an integer to drive the control value on my HOA’s. Is there a way to write an expression for the control value of the HOA to work with 3 individual bits instead of an integer?

I suppose it depends a little on how you have the value set up.

The simplest method, however, is probably to use the getBit() expression function.

So, if Auto is represented by bit 3 then this expression would return the value of that bit.


The function of hand, off and auto is set up as such. There are only two tags that drive this whole process, not ideal, I would never program it like this but I can’t change what’s in the plc so I have to deal with it.

Tags : Man_Off = Off, Man_On = Hand

If Man_Off = 1 & Man_On = 0, go into OFF mode

If Man_Off = 0 & Man_On = 1, go into HAND mode

If Man_Off = 0 & Man_On = 0, go into AUTO mode

This type of three-position switch is extremely common in the real world. They are typically set up so one input (Hand) is on in the left position, the other input (Auto) is on in the right position, and neither are on in the center position (Off). Which is where the “HOA” acronym comes from. This combination fails “Off” if a wire is cut or input burned out.

I would keep the tags as separate bits. Combine in the UI with binEnc() to yield a value to style/animate with, and make the actionPerformed of each button write to both bits.

1 Like

I agree with @pturmel that what you describe is fairly normal. Maybe what’s not normal, or at least not intuitive, is the tag names. It might have been better to say “Manual” and “Auto”. In my opinion it’s not necessary to put the state in the name, it’s implied by the name. If “Manual” is high then it’s in manual. Having a combination of the two is fine as well.

A link for binEnc() in case you need it:

I think binEnum() might be a better option, just my opinion though:

I disagree–it would hide the invalid combination of both being on.

It would? You can do this…

//BinEnum will return the index of the first parameter that evaluates true
    {Root Container.Manual_Off} && !{Root Container.Manual_On},
    !{Root Container.Manual_Off} && {Root Container.Manual_On},
    !{Root Container.Manual_Off} && !{Root Container.Manual_On}

Just used string as example.

Encode is the way to go.

case(binEnc({Off}, {Hand}),
0, "Auto",
1, "Off",
2, "Hand",
3, "Invalid State",
1 Like

Compare your complicated binEnum with just a binEnc of the two bits.

I would split the binEnc from the case so the numeric value is available for styling.

1 Like

I agree, except for the misuse of complicated. If you think that is complicated we are all in trouble. :slight_smile:

My example reads just like his post. In my opinion for some it’s easier to read. Not looking for a debate on this guys, just giving more than one way to do something.

This seems to work well on the indicator side, but on on the control variable side. It responds when I manually change the bits but not when I used the button to drive it.

Are the “bits” on the write side bidirectional, and the same tag?

they are and they are not the same tag, the HAND bit and OFF bit are completely separate tags

I meant the same “off” tag you write is the one you read, same for “on” What does happen when you use the buttons? Anything?

Works for the indicator value, will not work for the control value.

How do I drive the control value with two separate tags?

What component are you using, individual buttons, or something like a multi-state button?

You don’t. My recommendation is based on three basic buttons grouped together, each with an actionPerformed event script that writes to both tags. (Or writes to two bidirectional indirectly-bound custom properties.)

Would it be a reasonable idea to do a property change script on the control value (bound to binEnc expression), then write to the specific tags in there?

Edit, scratch binding, I don’t see a reason.

Multi state