12-28-2016 06:25 PM
Hello, maybe my question isn't smart but I am a beginner:
how can I use while loop in if statement? I mean how to build block diagram based on pseudocode:
if q<100
{
while (q<110)
q=q+1 //1 iteration per second
}
I've tried to do it with event structure but it has only event when boolean is changing value (problem - in my case I want it to be done only when changing value from 0 to 1 (q<100), not otherwise), case structure (problem - after 1 iteration case (q<100) isn't fullfilled)
My real case is pumping system which turn on the pump every time the flow is lower than 100 l/s and stop pumping when flow is 110 l/s
Thank you in advance.
12-28-2016 09:19 PM - edited 12-28-2016 09:21 PM
If you are a beginner, have you viewed any of the LabVIEW Tutorials? Taken any classes in LabVIEW (i.e. at school)?
You should have learned about the Case Statement, which mimic an If statement (if driven by a Boolean comparison, e.g. q < 100) or a Switch Statement (if driven by a integer numeric). What goes inside the Case structure is what you do in a Case (such as the "True" case of "q < 100"). One thing to remember about a While loop is that the loop always runs at least once, since the test to stop (or to continue) is applied after everything inside the Loop has run. You also have to remember the rules of Data Flow (and if you don't know what Data Flow means, go back to the first Video Tutorials).
Often, things that vary within a Loop are carried in Shift Registers -- the concept of a "Variable" (like "q") in text languages is, in LabVIEW, frequently carried in "wires".
Bob Schor
12-28-2016 10:20 PM - edited 12-28-2016 10:22 PM
Hi,
As a beginner be familiar with basic concepts in labview which is vastly available. For your query, here is a simple block diagram which runs when q<100 and stops when q>110. This is the basic concept. If you can give further information clearly, it will be useful !!
Hope it helps 😉
12-28-2016 11:10 PM
The case statement is directly analogous to a "select case" that you see in just about every text language. It's basicaly an "if-then" on steroids.
12-28-2016 11:16 PM
@wisniewski.energy wrote:
My real case is pumping system which turn on the pump every time the flow is lower than 100 l/s and stop pumping when flow is 110 l/s
I would suggest you try to solve the real case, instead of a problem that seems to have very little to do with it. 😄
All you need is a state machine that reads the flow at regular intervals and turns the pump on depending on the measured flow and the current state of the pump.
12-29-2016 02:49 AM
@wisniewski.energy wrote:
Hello, maybe my question isn't smart but I am a beginner:
how can I use while loop in if statement? I mean how to build block diagram based on pseudocode:
if q<100
{
while (q<110)
q=q+1 //1 iteration per second
}
Your answer is in your question. If you want a while function in an If statement, place a while loop in a Case structure. 🙂 From your description, though, this wouldn't get you closer to your goal. As Altenbach mentions, a State machine is probably the answer. (It's basically a case structure of States inside a while loop that sends/selects which state to do next, check Examples and New from Template)
/Y
12-29-2016 07:18 AM
Hi
Below i placed example code that is representing functionality described by your C code.
You can play with it and modify as you wish.
Please also read these documents to better understand how this example is working:
http://www.ni.com/white-paper/7588/en/
http://www.ni.com/getting-started/labview-basics/execution-structures#Case Structures
http://www.ni.com/getting-started/labview-basics/shift-registers
Please write a feedback if my answer was helpful.
Regards
12-29-2016 11:18 AM
@sprzysta wrote:
Below i placed example code that is representing functionality described by your C code.
This does not solve the real problem and is also not equivalent to the text code because q does not change here. It is generally a very bad idea to trap code inside inner loops for long periods of time, making it unresponsive to user intereaction.
The OP needs to (1) solve the real case. If external hardware is not available, a (2) simulation subsystem needs to be implemented that adjust the reading according to the states of the system.
12-29-2016 11:54 AM - edited 12-29-2016 11:55 AM
Here's a very primitive simulation system. maybe it can give you some ideas.
(For easy demonstration, it runs faster, so please adjust the timing if needed. In the real system, just replace the orange shift register and associated code with a reading from the flow gauge)
09-05-2019 07:03 AM
Hello,
Yes i need this type of stuff in my coding. I just implement till now the interfacing between the arduino and labview. I want to implement now this code into my arduino and control my arduino through one button which should be in Labview. Can you help me with VI.
Thanks