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: 

LabView problem with while loops.

Solved!
Go to solution

Hey guys, im working on a simple project where i have 2 analog liquid level sensors   that each gives below zero volt when being down and above zero when being up and i want to control the water through a mini water pump with mydaq.  I want the pump to open when both sensors  are down and close when both are up. So i have a while loop for the whole project and a mini while loop in a case condition which the programm goes when both sensors are down. My problem is when the programm enters the mini while loop it can not read  new values from the liquid level sensors inputs and  as a result i cant get out of the mini loop when both sensors are up. Any suggestion?

0 Kudos
Message 1 of 13
(1,877 Views)

Hi!

It would be much easier to figure out the problem, if you attach a vi or a block diagram screenshot.

0 Kudos
Message 2 of 13
(1,874 Views)

KatsanikJr_0-1599841270730.pngKatsanikJr_1-1599841291749.png

iv made up three states that the sensors can be . when 1st state appears the programma enters in the case condition as shown in the second picture which has a while loop and i want to stop the condition-while loop as shown but the values are not updated when running it. You can replace the sensors with numeric controls

0 Kudos
Message 3 of 13
(1,867 Views)

@Sam_Rudneff wrote:

Hi!

It would be much easier to figure out the problem, if you attach a vi or a block diagram screenshot.


A screenshot is practically useless. Attaching an actual vi is much preferred.

0 Kudos
Message 4 of 13
(1,853 Views)

Please attach your VI. truncated pictures are useless for us.

 

  • You have multiple while loops, so which one are you talking about?
  • What's in the other cases of the case structure?
  • Index array is re-sizable.
  • +0 does not do anything useful.
  • You can wire a boolean to a case structure directly. no need to convert it to 0,1.
  • All numerics derived from booleans should be Integers (blue, not orange). Do you know the difference?
  • You definitely don't need any value properties nodes.
  • You can probably simplify the code by using more arrays.
  • ...
  • ...
0 Kudos
Message 5 of 13
(1,844 Views)

Rarely is there a need for a while loop inside a while loop. You need to restructure this into a proper state machine.

 

Some other glaring issues in the screenshot that you shared:

 

1. You are mixing orange and blue lines. If you add a number to an integer then use an integer. Also, there is a +1 primitive that you can use.

2. Never test equality of floats.

3. I see local variables, meaning that there could be race conditions associated with your program. Use wires instead.

4. Your inner while loop is blocking - learn about THINK DATAFLOW. This will lead you toward a state machine design.

 

There are probably other things - these were just a few glaring issues.

0 Kudos
Message 6 of 13
(1,840 Views)

Thank you for your reply, i took under consideration your words and i tried to make a simpler programm to understand my problem. I attached the vi here . This vi works fine the problem is that i have inside the inner loop local variables that comes straight from the input controllers. The case which stops the inner loop is similar with the variable : state_3. If you try to replace state_3 as local variables instead of remaking the state inside the inner loop the programm will not work. 

 

My goal is when the programm enters the if case with state_1 to exit the case only when it reachs state_3 .

 

Moreover the inputs are reffered as upper and bottom sensor because im gonna take data through mydaq as shown in the 1st photo previously but since im working the project in the university i cannot take at home the mydaq board so i have to make 'iconic' inputs. Imagine that the sensors in this vi  are simply liquid level sensors so the water goes up and down. Thats why i want to run the pump when both sensors are down until they both go up. but when they are already up i want the pump to run again only when they both go again down..etc etc

0 Kudos
Message 7 of 13
(1,791 Views)
  • You don't have any local variables.
  • As has been said, you only need exactly one loop. The state determines the case.
  • What is "straight from the input controller"? Do you mean the front panel controls?
  • You need a proper state machine.
  • Your popups are blocking dataflow. Do you rally need them?

Please explain exactly how the VI is used, What you press and in what order, what you expect, and what happens instead.

0 Kudos
Message 8 of 13
(1,762 Views)

Why do you think that you need the inner loop? Just use the outer loop (you're really close to a state machine already). Then you won't have to use the value property nodes inside the loop.

 

Also, why do you convert the boolean to a number and then use >0 to convert it right back to a boolean? That's pure Rube-Goldberg. Use the boolean directly. You can use a NOT to get the same result as your <=0.

 

As altenbach mentioned you have blocking dialogs in your code. I suspect that you want the code to continue running. Consider just putting a message box on the screen instead.

 

Also, I noticed that you're using 3 second loop times. I would recommend dropping that. Users will become impatient with waiting 3 seconds after pressing a button to get a response.

0 Kudos
Message 9 of 13
(1,753 Views)

@johntrich1971 wrote:

Also, why do you convert the boolean to a number and then use >0 to convert it right back to a boolean? That's pure Rube-Goldberg. Use the boolean directly. You can use a NOT to get the same result as your <=0.


Even simpler. 4 booleans can have exactly four conditions, so just do lookup tables, e.g. as follows. No need to overthink this ;):

 

altenbach_0-1599939240264.png

 

Message 10 of 13
(1,749 Views)