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?
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.
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.
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.
//BinEnum will return the index of the first parameter that evaluates true
switch(binEnum(
{Root Container.Manual_Off} && !{Root Container.Manual_On},
!{Root Container.Manual_Off} && {Root Container.Manual_On},
!{Root Container.Manual_Off} && !{Root Container.Manual_On}
),
1,2,3,
"Off",
"Hand",
"Auto",
"Unknown")
I agree, except for the misuse of complicated. If you think that is complicated we are all in trouble.
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.
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?