LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simplifying Code - Connected Variables

Solved!
Go to solution

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. 

0 Kudos
Message 1 of 8
(2,473 Views)

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…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 8
(2,436 Views)
Solution
Accepted by topic author JTCLARKE
0 Kudos
Message 3 of 8
(2,404 Views)

Note that if you want to eliminate the event structure and do polling instead (Maybe this involves hardware), it's not really more complicated:

 

altenbach_0-1613679956283.png

 

0 Kudos
Message 4 of 8
(2,393 Views)

@altenbach wrote:

Here's what I would do:

 

altenbach_0-1613677922286.png

 



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.  

0 Kudos
Message 5 of 8
(2,387 Views)

@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

0 Kudos
Message 6 of 8
(2,386 Views)

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

0 Kudos
Message 7 of 8
(2,365 Views)

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.


 

0 Kudos
Message 8 of 8
(2,302 Views)