From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event structure vs case structure?

Solved!
Go to solution

I am developing an application that is fairly user input based... lots of boolean control buttons to do different things.

 

In the past, I have avoided "value change" event structures, and instead went with a while loop, stacked sequence, and series of case structures. After having done it, I decided this was a terrible idea. This time, I intend to build an array from the booleans, convert it to a number, and feed it in to a single case structure. This will give me the option to add cases for different combinations of the booleans being pressed.

 

I guess the question is: What is the best method for doing something like this?  Does one have advantages over the other?

 

 

Edit: I wasn't that clear.  I would like a comparison between the "value change" event structure method, and just feeding everything in to an array -> case structure.  I also am worried that with the bool array -> case structure that I will run in to problems where I end up with too many control variables, and the value of the resulting number gets ugly very quickly. The application has several buttons... next, last, save, load, several different configure setup buttons etc.

 

Thanks!

Message 1 of 12
(6,657 Views)

@Aalenox wrote:

I am developing an application that is fairly user input based... lots of boolean control buttons to do different things.

 

In the past, I have avoided "value change" event structures, and instead went with a while loop, stacked sequence, and series of case structures. After having done it, I decided this was a terrible idea. This time, I intend to build an array from the booleans, convert it to a number, and feed it in to a single case structure. This will give me the option to add cases for different combinations of the booleans being pressed.

 

I guess the question is: What is the best method for doing something like this?  Does one have advantages over the other?

 

 

Edit: I wasn't that clear.  I would like a comparison between the "value change" event structure method, and just feeding everything in to an array -> case structure.  I also am worried that with the bool array -> case structure that I will run in to problems where I end up with too many control variables, and the value of the resulting number gets ugly very quickly. The application has several buttons... next, last, save, load, several different configure setup buttons etc.

 

Thanks!


Event structure. Among other things, it will allow your loop to "sleep." then wake up when an event happens. With a case structure it's going to be constantly polling. Event structure is pretty much always the right way to go in newer versions of LabVIEW that have it available. I assure you, your first solution was aboslutely wrong and you noticed that, your second is better and was common the way before event structures existed, now that event structures exist, you should go with those.

Message 2 of 12
(6,640 Views)

I attached a VI as an example of what I mean.

0 Kudos
Message 3 of 12
(6,639 Views)

I edited my response: see above.

0 Kudos
Message 4 of 12
(6,636 Views)

for(imstuck) wrote:

Event structure. Among other things, it will allow your loop to "sleep." then wake up when an event happen. With a case structure it's going to be constantly polling. Event structure is pretty much always the right way to go in newer version of LabVIEW that have it available.


I don't want the loop to sleep though because it will be processing things while running. What it is processing etc is dependant on the value of the switch booleans, if all are off then it is processing nothing. If one or more is on, the program will be crunching data.

 

I guess that I could do two separate loops running simultaneously.

 

Another simple question would be:  is there any good discussion / tutorials you know of for developing the "main vi" for larger applications?  To date what I have done has been fairly small programs for a single application. Even those have a tendancy to get haneous.

0 Kudos
Message 5 of 12
(6,634 Views)
Solution
Accepted by topic author Aalenox

Aalenox wrote:

 

 

I guess that I could do two separate loops running simultaneously.

 


^^^^ THIS!! 

 

Search for producer consumer architecture

Message 6 of 12
(6,627 Views)

The event structure is pretty usless in your case, because you are spinning the loop anyway as fast as it can to poll the switch action buttons. DOes the loop really need to spin constantly or do you only need to update things if any of the buttons change?

Your diagram comments talk about adding more and more buttons. Have you considered using an array of buttons instead?

 

I don't understand why you are so drawn to stacked sequences..... They are almost never needed.

Message 7 of 12
(6,625 Views)

@altenbach wrote:

The event structure is pretty usless in your case, because you are spinning the loop anyway as fast as it can to poll the switch action buttons. DOes the loop really need to spin constantly or do you only need to update things if any of the buttons change?

Your diagram comments talk about adding more and more buttons. Have you considered using an array of buttons instead?

 

I don't understand why you are so drawn to stacked sequences..... They are almost never needed.


I agree the event structure in this case is useless, unless I have two loops running simultaneously.  One loop does need to spin constantly, IF one or more of the 'switch' booleans are on. If so, it is collecting and processing data.

 

I hadn't considered an array of controls before. Any good examples you'd consider going over?

 

I was initially drawn to stacked sequence structures because it solved the problem of ... for lack of a better term, "visual real estate". I could control the data flow easily and just flip from pane to pane, allowing for a LOT of code in a single VI.  That having been said, as I am getting better at LabVIEW I have started to realize this is the wrong approach to take. So - part of this post is about coming up with a better method 🙂

0 Kudos
Message 8 of 12
(6,623 Views)

State machines are a lot more expandable than sequence structures.

 

With an array of buttons, you could autoindex the array with a FOR loop and then you have a case structure to decide what to do.  It's a form of a state machine I guess.

 


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 9 of 12
(6,609 Views)

Thank you all for your replys :). I have found this:

 

http://expressionflow.com/2007/10/01/labview-queued-state-machine-architecture/

 

which looks quite useful. If anyone has any additional reading they would suggest, please post it. It seems that as of now, I am going to have to greatly revamp the way I do my archetecture for programs. My old way won't cut it.

0 Kudos
Message 10 of 12
(6,603 Views)