LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using stop button boolean in case structure

Hello all,

 

I'd like to use the boolean from pressing "Stop" in an inner loop to execute some code inside a case structure. My issue is that the button always sends true (I tried with and without negation).

 

When the case structure does receive false, I'd like to execute some code and send constant true to break statements within the current loop. My problem here is that the loop breaks without ever executing the code in the case structure.

 

Any feedback is much appreciated.

 

Thank you.

0 Kudos
Message 1 of 24
(486 Views)

You are merging several booleans of various flavors (plain, inside dynamic wires, etc.) into a new dynamic data wire and I doubt you know what really happens if you wire that to a case selector that can only deal with one value. Most likely it grabs the first it sees, which is from the comparison of the first element of the absolute voltage array.  Don't use dynamic data for that! 

 

Your code is a giant mess. As a first step, eliminate that pyramid of 3 stacked while loops and replace it with a single while loop and a state machine architecture (your outer loop has no purpose whatsoever!). There is no logic in the current design.


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 2 of 24
(474 Views)

Altenbach,

 

Many thanks for an extremely informative response. I didn't know there was a formal implementation for state machines in labview! Thanks.

 

In the meantime, I'd like to better understand the various booleans. Is there a button that supplies a boolean which would play nice with the case structure?

 

Also, why doesn't the code inside the case structure execute when the case structure sees false? It only sends the constant boolean out to the break statements without executing the code.

 

Thanks for your time, I do appreciate your help.

0 Kudos
Message 3 of 24
(439 Views)

I don't understand your comments and questions.

 

All booleans play nice with case structure.  A boolean wired to a case structure gives you two cases, True and False.  It will execute all the code in the True case when the boolean is True, and all the code in the False case when False.

 

I don't know what you mean by "break statements" as I don't see anything in your code that resembles that.

 

I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
Learn LabVIEW

0 Kudos
Message 4 of 24
(435 Views)

The red button in the loop which breaks execution in that loop is the break statement. This same convention is used in java, c++, python, and more.

 

As I mentioned in my first post, pressing the "Stop" button seems to send true, even if I add a negation. This is the meaning of my comments and questions.

0 Kudos
Message 5 of 24
(425 Views)

If you want that little case structure to react to the boolean wire, wire that thin green wire to the case structure and don't merge it with dynamic data full of other stuff.

Dynamic data is very opaque and we have no idea what's in it just by looking at a diagram. Most advanced users avoid dynamic data entirely.

As I said, the outermost loop only spins once and if you would delete it, nothing would change.

 

Do you really need to configure the output in the outer loop with every iteration then close it? Once your program runs, the initial inputs are never read again. Maybe you should disable these controls during run (Or use diagram constants instead if they are always the same).

 

LabVIEW ships with many design templates, including state machines. You can also look at shipping examples and search the forum.


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 6 of 24
(408 Views)

@phillipcurtsmith wrote:

The red button in the loop which breaks execution in that loop is the break statement. This same convention is used in java, c++, python, and more.

 

As I mentioned in my first post, pressing the "Stop" button seems to send true, even if I add a negation. This is the meaning of my comments and questions.


That is the wrong terminology.  That "red button" in the loop is called a stop condition terminal.  Break statement implies a breakpoint placed somewhere in your code.

0 Kudos
Message 7 of 24
(395 Views)

Wiring the green trace directly to the case structure results in the same behavior. With or without a negation, the case structure only sees true. I also tried changing the button to "latch when pressed" with no luck.

 

I see now that I don't need that outer most loop. I'll delete it when I have the correct behavior. I don't want to change too much at one time while just getting things working.

0 Kudos
Message 8 of 24
(382 Views)

@phillipcurtsmith wrote:

With or without a negation, the case structure only sees true. I also tried changing the button to "latch when pressed" with no luck.


Then show us your latest code and tell us exactly how you are determining the case that executes. (preferably strip out all the DAQ stuff and replace it with some simulated data, but otherwise retaining the behavior.

 

The green wire going to the small case structure is either true or false, depending on the reason why the inner loop stopped. Case structures existed since LabVIEW 1.0 and work properly. The error must be in your code. Connect an LED on the boolean output of the case structure to observe.


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 9 of 24
(377 Views)

I stripped the code down to the essentials. I did keep some DAQ stuff because the data type (dyanamic data?) seems to be part of my problem.

 

I wired a constant true from the false side of the case structure to an LED. The LED never lights, with or without negation.

 

Both sides of the case structure still send false to the "stop condition terminal" (thanks RavensFan) since setting either to true causes the stop condition terminal to trigger without executing any code in the case structure.

 

Before I sent this, I did try a version without any DAQ content whatsoever. I used only the boolean values from the timer subvi and button press. This worked fine to get a true or false to the case structure from the button. 

 

I appreciate your help, thank you.

0 Kudos
Message 10 of 24
(366 Views)