Case Structure Nested in a For Loop

I have two pumps. I want one pump to be running and the other pump to be off. Then as soon as the first pump stops I want the other pump to start. I'd like this process to repeat as many times as I want. The code I have now uses a case structure inside a for loop. When the iteration is odd it is false and even is true this determines what case is carried out. Right now I have a code that can turn on one pump, stop it, and immediately start the second. However, after the second pump stops the first one does not start again. I've changed the number of iterations and I can't seem to get the process to continue. The program keeps running but the pumps stop doing anything. Attached is a file of my code as well as two image files (one showing true case and other showing false) of the same code.
Attachments:
Test Code 1.vi ‏31 KB
Case if True.png ‏37 KB
Case if False.png ‏35 KB

Your code has an inner while loop that checks for the status of the pump.  Since you set up a target volume before the while loops start, I assume that it is what the status checks to determine when to stop the while loop.
When the the second iteration ends, has the volume for the first pump changed at all?  If it is still the same, then the status is still at the target which means it will immediately stop after starting.  You may also want to put some small wait statements inside the inner while loops so that the status isn't checked as fast as the CPU will allow it to run eating up CPU cycles.

Similar Messages

  • Unable to put a timed structure in a parallel for loop, error -808

    If I try to place a Timed Structure in a Parallel For Loop, the TS needs a different structure name per instance to prevent collisions. However, setting the Structure Name node  to something unique per instance doesn't work, I get error -808. Have I missed something?
    Thoric (CLA, CLED, CTD and LabVIEW Champion)

    That got me thinking - something to do with the number of compiled parallel instances.
    Indeed, the compiler creates a number of parallel instances of the for loop in the compiled code (in my case 8), and uses the number requested at the Parallel Instances terminal (just under the Iterations terminal), which is set to 2. Therefore the compiler has created 8 instances of the Timed Structure, each in its own for loop instance, but they all have the same defined Structure Name. When launched, there is an immediate conflict because they can't share the same name, and error -808 is launched before the set Structure Name function can change it. Hence the error still shows when requesting only one instance, because the other seven still exist.
    I guess this means you can't have Timed Structures (or Timed Loops for that matter too) in a Parallelised For Loop?
    Thoric (CLA, CLED, CTD and LabVIEW Champion)

  • Is it possible to use a "for loop" structure to represent DAQ of 16 channels?

    Hi,
    I tried to search but I failed to find a similar problem so I am posting this problem here.
    I have a temperature DAQ board which has 16 channels, and I am using all 16 channels to record and monitor temperature data.
    When I writed blocks for all 16 channels, a mess was created (as you can see in my attached program). I have noticed that all the VIs for the 16 channels have similar structure, so I was thinking whether we can represent all 16 channels with a "for loop" strucutre with a pointer i scanning from i=1 to 16 as we usually do in Matlab or Fortran.
    For instance, we may try to simplify the code like:
    for i=1:1:16
         acquire data from channel i
         show data from channel i in X-Y graph
         write data from channel i to excel in every 10 seconds
    end  
    I could not do it myself because I cannot find a "pointer" to represent each channel.
    Does anyone know how to do this in LabVIEW? Thank you.
    It is said that it is best if we can put all of our code within the screen of a monitor we use by using subVIs to divide the code into many subroutines. But I found it quite difficult to do so as I have too many controls as inputs and indicators as outputs. Also, I use property node to read and write frequently, which make things harder....
    Attached code does not work as it requires the 9213 hardware, and for simplicity I deleted irrelavent modules. But if you need I can upload one that may work by modifying the read VI.
    Thank you.
    Attachments:
    ask for help.vi ‏132 KB

    Yup, instead of all these 1D arrays, use a single 2D array. Your code could be reduce to <10% of the current size. I am sure it would fit easily on a single screen.
    Also try to do some tutorial or take some courses. I realy don't think you are ready to tackle a system of this magnitude at this time.
    Your code is just peppered with very poor choices. Some things you apparently haven't figured out:
    index array is resizable. There is no need to create dozens of parallel instances, all wired to the same array and all with a unique index diagram constant. If you want all elements in order, the indices don't need to be wired at all.
    Replace all your value property nodes with local variables. Much more efficient. Then redesign the code so you don't even need most of the local variables.
    You can use built array to append elements to an existing array. Using "insert into array" is much more complicated an error prone.
    It is not a good idea to have deeply stacked while loops with the innermost loop having long delays and indeterminate stop conditions. That just gums up the gears.
    Learn about proper code architectures, state machines, etc.
    Get rid of that gigantic, all encompassing stacked sequence. I am sure you can find a better way to reset three booleans when the code is about to stop. In fact it is typically more reasonable to set things to a defined state when the program starts to avoid problems due to accidental value changes at edit time.
    Don't use hidden control/indicators as data storage and interloop communication via local variables. There are better ways.
    You can wire the reminder or Q&R directly to a case structure. No need for e.g. "=0".
    Don't use ambiguous labels, e.g.a boolean labeled "Dampers on or off". Nobody will be able to later figure out if TRUE corresponds to ON or OFF. Could it be that TRUE mean it is either ON or OFF and FALSE that it is in some imternediate position?
    LabVIEW Champion . Do more with less code and in less time .

  • How to stop and start a for loop

    I've got code and a for loop running in a while loop.  What I need to do is simply pause the operation of the for loop until an requirement is met, and but maintain its iteration position throughout each pause interval (not necessarily timed, just paused until the next requirement is met).  I've tried wiring a boolean to the "continue if true" terminal of the for loop, but the iteration count restarts to 0 when the loop is started again.  Is there a way to stop the for loop, and continue at the particular iteration it is at?
    Solved!
    Go to Solution.

    Breakpoints, whether normal or conditional, are just meant for debugging of your code.  I had the sense from your question that the pausing you want to do is a part of normal operation of your code.  I would NOT recommend using a breakpoint for that situation.  It would bring up the block diagram showing the breakpoint when it occurs.  A user besides the programmer would not know what to do in that case.
     Yes, both the inner and outer loops would have shift registers.
    Putting a case structure with a small while loop inside the "Pausing Case" is doable.  It just depends on what you are doing or waiting for while the program operation is "paused".

  • Event structure or case structure

    I have some case structures wired to buttons.  When each button is true, code inside the corresponding case structure executes.  `What are the advantages/disadvantages of using an event structure instead of a case structure?
    Ron Deavers, CLD

    Place an indicator for the iteration terminal of the main loop to see an obvious difference
    Your case structures must be in a loop that constanty runs. If you don't put a delay in the loop, it consumes all CPU, but if your delay is too long, it takes a moment to react to the button changes. The loop spins all the time, no matter if you press buttons or not.
    Your event structure also sits in a loop, but nothing happens until you press a button. Now the event structure triggers IMMEDIATELY, executes the event case, and then waits for the next event. The loop does not spin unless needed.
    You can even mix the functions by using a timeout event. Code in the timeout event occurs at regular intervals, but at any time, any of the other events can take over.
    LabVIEW Champion . Do more with less code and in less time .

  • Build array of elements in a for loop

    Hello, I have a program where I am taking voltage measurements and computing resistances inside of a for loop. I then want to take these values an place them in individual arrays which are then sent to another subVI to compute the mean and standard deviation. Currently it appears the arrays are getting overwritten and only one value is stored in the array. Please let  me know what I have to do to fix this. Thank you.
    I have attached my VI and the area I am talking about is in the case statement inside the big for loop for case 1.
    Message Edited by BJalbert on 05-25-2007 09:57 AM
    Attachments:
    StdTest2.vi ‏159 KB

    The image shows two possibilities:
    Still, you should really simplify your data structures. For example you could have all your 7 results as a single 1D array and built it as a 7xN 2D array, etc. You probably can reduce the clutter on the diagram by 90%!
    It is a nightmare to deal with subVIS containing so many individual connectors.
    Message Edited by altenbach on 05-25-2007 08:24 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ArrayBuildingInLoop.png ‏5 KB

  • Tunnel mode: indexing with a case structure

    Hello,
    I have a code like the one  attached to this message.
    I have a case structure in a while loop, and I would like to transfere some data from my case structure to outside the while loop in indexing mode tunnel.
    This is to accumulate results (or to save results) following each iteration.
    My problem:
    I dont want any value in the False case of the case !!
    How can I get rid of that? I do not want to use default value for unwired case and I dont want 0. 
    Many thanks 
    Attachments:
    Untitled 1.vi ‏9 KB

    Your VI is saved in LabVIEW 2014.  So you should have this.  Right-click on the output tunnel of the loop.  There is a tunnel mode->conditional.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Conditional Indexing Tunnel.png ‏7 KB

  • What is the best way to pass a controllin​g signal out of a sub vi or more than one layer of for loop, while the sub vi or for loops are still running?

    I have a vi that runs through two for loops and a while loop, then after a certain number of iterations on the inner while loop it is supposed to pass a trigger to a case stucture to start measurement. I have tried using a local variable attached to a boolean control which in turn is attached to the true case of the case structure involving the measurement sub vi. What is happening is that the boolean control will light on the front panel at the correct # of iterations in the while loop, as if true, but the measurement is not taken, and the boolean control never goes back to false. It remains lit. Am I u
    sing the local variable incorrectly? If so, where am I going wrong.
    Attachments:
    GL_Flicker.vi ‏118 KB
    Take_Measurements.vi ‏147 KB

    Hello planar,
    There are multiple ways to pass control information between loops and VIs and each one has its place. For simple VIs like your example, a local variable will be fine.
    The main reason the subVI is not running is that the case structure is not continuously polling the Boolean control. This is because the case structure is not inside a loop and as such will only read the Boolean value once and execute once. Encasing the case structure and control inside the while loop should solve the issue of the subVI not running.
    You may find the following links of help in creating more robust and advanced VI architectures.
    Application Design Patter
    ns: Master/Slave
    LabVIEW Application Design Patterns
    Keep up to date on the latest PXI news at twitter.com/pxi

  • Possible to do this with case structure?

    Essentially I want the case structure to do: If case1 = run OR case2 = run, do this, else do case3++
    I'm using a string case structure right now, where for example, the inputs could be SWEEP_A or SWEEP_B but I want the case structure to use case SWEEPAorB. This is so I can have different names for the input string BUT run the same case (this is to avoid redundant code for what I'm doing).
    Thanks.

    For more complex logic use can use create a boolean array and convert it to a number.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Resetting a for loop counter and restarting the computation

    I have a while loop nested inside a for loop to do a calculation of a model. 
    Lets say I am on the for loop counter 4. Suppose I wanted to keep track of the number of iterations on one the while loop, and if it exceeded a certain number say 100, exit the while loop.  I am doing this to avoid my model calculation being stuck at a spot due to optimization issues. I now want to restart the calculations of for loop counter 4. 
    Is there a way to do this in labview? 
    Solved!
    Go to Solution.

    Well first of all, if you are going to restart the loop with the same program inside it after it got stuck is it not just going to get stuck again creating a permanent loop in the code? Would you not just want to move on and have some sort of identifier that one of the for-loops got stuck?
    But I would recommend simply nesting your while-loop inside of another while loop, then connect the exit for the out while-loop to some variable from the inner while-loop, so if the optimization did not occur properly then it simply repeats the inner while-loop.
    Although I stick by my thoughts that you will just end up in a permanent loop if the optimization fails the first time.

  • The demand of my application is that i can not replace for loop with a while loop.because i need fixed number of iterations and as far as i know fixed iterations could be only with possible with the for loop.

    the demand of my application is that i can not replace for loop with a while loop.because i need fixed number of iterations and as far as i know fixed iterations could be only with possible with the for loop.
    your recommended second option that i could add true/false case.
    this true/false case must be inside the for loop or outside the for loop?if this case is inside the for
    loop, how can i send stop command from outer while
    loop?
    more over do you have any example for this please?
    thanks"

    You can execute a fixed number of iterations using a while loop by comparing the iteration count to the number of iterations you want and wiring the output of that comparison (e.g. Less Than or Equal To) to the continue (or stop) terminal of your while loop. Which comparison you use depends on personal preference, where you wire the desired count and the interation count, and whether you're using the while loop as Continue if True or Stop if True.
    Ben gave you step-by-step instructions in response to your previous question. Look here for Ben's response.
    Ben's response looks pretty good and detailed to me. It certa
    inly deserved better than a 1-star rating.

  • For loop, strings and case structures.

    how do i pass out only a TRUE case string without passing the FALSE case? this is running in a FOR loop so im creating a string array, but i dont want empty elements where the default FALSE value has been tunneled out(ie the loop has N=5, so a string array of 5 elements is created) how can i end up with an array that contains only the TRUE case strings(ie N=5, but an array of only 2 elements)

    You need to use an approach which doesn`t use auto-indexing the tunnel leaving the FOR loop. I have included an example.
    Shane.
    Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
    Attachments:
    Case_statement-selective_array_build.vi ‏22 KB

  • How to get a case structure to execute only once in a loop

    I have a while loop that is monitoring temperature. Once the temperature meets or exceeds a given setpoint I want to start a timer. At this point I don't want to monitor the temperature anymore. That is, if the temperature should drop below the setpoint, I don't want to execute the case structure again when the temperture meets or exceeds the setpoint(the temp may oscillate about the setpoint for a given period of time). In any event, I need the case structure to execute only one time, not every iteration of the loop.

    You can put a local Boolean variable "Flag" inside that case structure and
    set "Flag" to False. Outside the case structure, use an "AND" function
    output to control the case structure. The "AND" function has two inputs. One
    goes to the comparison results between real temp and setpoint. The other
    inputs connects to the "Flag" variable. In this way, once you entered that
    case structure, the "Flag" will be turned to False, and then in next
    iteration, you won't get into the case again because the "AND" function will
    be False as your "Flag" is False now.
    Hope this helps.
    Rentian
    1. Inside the case structure, put a
    "BB Herman" wrote in message
    news:[email protected]..
    >I have a while loop that is monitori
    ng temperature. Once the
    > temperature meets or exceeds a given setpoint I want to start a timer.
    > At this point I don't want to monitor the temperature anymore. That
    > is, if the temperature should drop below the setpoint, I don't want to
    > execute the case structure again when the temperture meets or exceeds
    > the setpoint(the temp may oscillate about the setpoint for a given
    > period of time). In any event, I need the case structure to execute
    > only one time, not every iteration of the loop.

  • Nested for loop in Xquery

    hi all,
    I need to implement nested for loop in Xquery, but not able to do. Please help.
    Thanks in advance..
    Rajan

    Nested for loops are simple in Xquery. Here is a very basic example:
    Input:
    <root>
    <FirstLevel>
         <SecondLevel>
              <Value>1</Value>
         </SecondLevel>
         <SecondLevel>
              <Value>2</Value>
         </SecondLevel>
         <SecondLevel>
              <Value>3</Value>
         </SecondLevel>
    </FirstLevel>
    <FirstLevel>
         <SecondLevel>
              <Value>4</Value>
         </SecondLevel>
         <SecondLevel>
              <Value>5</Value>
         </SecondLevel>
         <SecondLevel>
              <Value>6</Value>
         </SecondLevel>
    </FirstLevel>
    </root>XQuery:
    declare namespace ns0 = "http://temp.uri/OTM";
    declare function ns0:NestedForLoop($input as element(*))    as element(*)
         <ns0:Output>
              for $firstLevel in $input/FirstLevel
              for $secondLevel in $firstLevel/SecondLevel
                    return
                  <element>{ $secondLevel/Value/text() }</element>
         </ns0:Output>
    declare variable $input aselement(*) external;
    ns0:NestedForLoop($input)Output:
    <otm:Output       xmlns:otm="http://temp.uri/OTM">
         <element>1</element>
         <element>2</element>
         <element>3</element>
         <element>4</element>
         <element>5</element>
         <element>6</element>
    </otm:Output>Of course, this case is very simple and usually you wont even loop for this you can use a simple XPath like $input/FirstLevel/SecondLevel/Value/text() to achieve the above result. So, If you are having problems in a specific case of nested for loops, please post the input and output here and we can help out.

  • Multiple booleans controlling one boolean input for a case structure

    Hello,
    I have four boolean buttons and a case structure with a boolean input. I would like to write the program so that whenever any one of the four boolean button changes value, the case structure reads true for one loop interation, and then returns to false.
    I have tried all sorts of things and can't seem to figure it out.
    Ultimately, the ideal function of the program is so that whenever you push any one of the four boolean voltage controllers, that voltage case is chosen in the case structure, the time in seconds is written to a file, and the elapsed time timer is reset.
    I have attached my program. Let me know if you have suggestions. Thanks.
    Attachments:
    Volt_Control_And_Time_Counter.vi ‏71 KB

    Zappow wrote:
    However, with this setup, the time counter still doesn't work.
    The event structure for all four buttons has a true boolean constant connected to my file-saving case structure. If I connect this to my elapsed time express VI reset button, the timer doesn't count.
    The timer does not count because you have not wired a timeout to the lower event structure. The default timeout is -1, so the lower loop never spins via timeout
    It is useless to have a wait in a loop that also has a timeout case. Just wire an approriate timeout value to the timeout terminal and remove all waits. It is also not necessary to have a 1ms ttimeout if your timeout values only displays to 100ms resolution. Can you explain why you think you need two loops and all that extra code?
    Attached is a quick rewrite that solves some of the problem. Since I don't have any hardware, I replace the voltage out with a meter.
    You have way too many FP controls and indicators. Use arrays!
    Let me know if yo have any questions. Modify as needed.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Volt_Control_And_Time_CounterMOD.vi ‏63 KB

Maybe you are looking for

  • Can I sync the same iTunes library on both my iMac and my MacBook Pro?

    Can I sync the same iTunes library on both my iMac and my MacBook Pro?  I've been connecting my iPhone to each and it's causing problems for me with them being different, despite my purchases always being under the same Apple ID.

  • My iPod Touch 4th Gen won't connect to the internet!

    Recently whenever I try to connect to our home wifi it hasn't been connecting, all that comes up is that loading spinning circle thing that means it's trying to connect. No matter how long I leave it, it doesn't connect. I don't think it is the route

  • CS and CR2 - apparently not a match made in heaven  :^/

    Hello all! I just bought a Canon 30D this week. I shot with it for the 1st time this weekend - I was so excited to get home and open my RAW files but I'm having real trouble. The Canon 30D is producing CR2 images (camera raw 2 I am guessing.) CS is n

  • Download Reports in CSV or pdf format

    Hi to all, i'm trying to download a report in CSV format that implicate the list of more than 400.000 users and their resource assigned. As i know, Sun IDM before generating this file is going to execute a task that return the list of this 400.000 us

  • Need simple ABAP OO reports, BAPI's and BDC upload using flat file.

    Hello experts, I am currently practicing ABAP and I would like to request some example codes for ABAP Objects, BAPIs, BDC's, etc. Thanks!