02-18-2021 01:28 AM
Please see my attached VI that is used to control a Lamp Head. The head has a total of 7 "zones" with each zone except Zone 1 having a complemented zone on both sides of the center Zone 1. I want the operator to be able to click either zone complement to get both to either turn on or off. The VI attached does work and uses shift registers, however it seems so much more complicated than I think it needs to be. One thing to note, when communicating to the external lamp head, only 7 Boolean values need to be sent, 1 for each zone. Showing both complements of each zone (greater than 1) is really just so operation is clear to the user so it matches the physical lamp head.
I apologize if my description isn't clear. I hope my attached functional code will help. Thank you guys for any recommendations.
Solved! Go to Solution.
02-18-2021 04:01 AM - edited 02-18-2021 04:04 AM
Hi JTClarke,
@JTCLARKE wrote:
Thank you guys for any recommendations.
I would use code similar to this:
It's just a sketch, and needs improvements like initializing the feedback node or maybe using Reverse1DArray depending on your "zone" arrangement.
In the end it reads the 7 buttons, ORs the 3 "side complementary zones", stores internally just 4 bits and converts those 4 bits back to 7 bits for output purposes…
02-18-2021 01:54 PM
02-18-2021 02:26 PM
Note that if you want to eliminate the event structure and do polling instead (Maybe this involves hardware), it's not really more complicated:
02-18-2021 02:34 PM - edited 02-18-2021 02:38 PM
@altenbach wrote:
Here's what I would do:
This solution is exactly what I was looking for. I wanted to integrate this into my existing from Panel UI Event structure loop anyway. This solution couldn't be better.
Wow I am just still in awe at how simple but effective you made this code. Thank you again.
02-18-2021 02:37 PM - edited 02-18-2021 02:37 PM
@GerdW wrote:
Hi JTClarke,
@JTCLARKE wrote:
Thank you guys for any recommendations.
I would use code similar to this:
It's just a sketch, and needs improvements like initializing the feedback node or maybe using Reverse1DArray depending on your "zone" arrangement.
In the end it reads the 7 buttons, ORs the 3 "side complementary zones", stores internally just 4 bits and converts those 4 bits back to 7 bits for output purposes…
Thank you GerdW. Your solution works well too. I appreciate your reply on this but feel the event driven structure solution fits the bigger application a little better.
Thank you again though for your help.
-John
02-18-2021 03:59 PM
@JTCLARKE wrote:
This solution is exactly what I was looking for. I wanted to integrate this into my existing from Panel UI Event structure loop anyway. This solution couldn't be better.
One small note here:
The code will work fine as long as the user is the only one interacting with this control. If you plan to ever fire this event using a signaling property node, be aware that old and new can be the same or differ by more than one element. If this is a concern, you need to add some code to deal with these possibilities.
02-19-2021 11:21 AM
Thank you. Thankfully this will be driven by a single HMI by one person. We shouldn't run into this issue.
-John
@altenbach wrote:
@JTCLARKE wrote:
This solution is exactly what I was looking for. I wanted to integrate this into my existing from Panel UI Event structure loop anyway. This solution couldn't be better.
One small note here:
The code will work fine as long as the user is the only one interacting with this control. If you plan to ever fire this event using a signaling property node, be aware that old and new can be the same or differ by more than one element. If this is a concern, you need to add some code to deal with these possibilities.