How do I run two while loops independent of each other?

I have a simple VI. I have loop 1 with and LED and a stop button and I have loop 2 with an LED and stop button.  They are both in while loops.  When I run the VI,if I stop loop 1, I can not turn it back on.  If I stop loop 2, it will not stop.  I've attached a file with my VI.  
Attachments:
2 Loops.vi ‏9 KB

bebesbabe,
This looks like a learning exercise, so I will not present a complete solution.
1. It is not polite to post to the Forum a VI which will not stop except by pressing the Abort button.  The Abort button should only be used to stop a VI if something is wrong with the program during development. Add a stop button to the outer loop.
2. A loop with no delay will try to run as fast as possible, consuming all the CPU resources it can get. Since these loops are for user interfaces, delays of 100 to 200 ms are appropriate. Use the Wait (ms) function.
3. Your main problem is understanding dataflow. In LabVIEW any node may execute only when all of its inputs have been given data and it will not complete its execution until all nodes inside it have completed.  Your VI does not have external inputs so waiting for data is not a factor. Each loop is considered a node. So the outer loop will iterate only after BOTH of the inner loops have stopped.  On the next iteration both inner loops will be started again.  Of course if the stop buttons are still pressed, the will stop after one iteration, which will seem almost instantaneous. But because of dataflow as I have described, your program cannot really work the way you want. You cannot restart one loop until both have stopped. Put an indicator on the "i" terminal of the outer loop.
4. You may wish to consider changing the mechanical action on your stop buttons to Latch when Released.  Read the help to learn about mechanical actions.
The way the instructions on the front panel read, it is not clear what the intended solution is. What control or user action or program action is required to turn the loops back on? Changing the stop button?  Automatically after a delay? A separate On switch?  How is the entire program supposed to stop?
Lynn

Similar Messages

  • Can we run two while loops independently in one application?

    I am acquiring two channels using PCI-6052.both channels to be read at 2ks/s,but I want to scans read at a time different for each channel,So I put two AI-read vi's in two different while loops.but the second while loop waits until the first is completed.Can we run independently both while loops?

    Dear Haider Abbas,
    you can scan two different channels at the same time with the same AI Read if your hardware device is cabable of it, e.g. you must have one A/D converter for each channel. If you have one A/D converter only and your channels are multiplexed then it won't work.
    You can try running both loops indepentendly by using delays but in this case the data acquisition will not be at the same time. You have also to consider that every time you call for AI Read the DAQ card will be initialised with takes some time
    Hope this will help you.
    Stephan

  • How do I unsync two I phones from receiving each others text messages?

    How do I unsync two I phones from receiving each others text messages?

    To fix this you have two choices:
    On one of the phones go to Settings>Messages>Send & Receive, tap the ID, sign out, then sign back in with a different ID (you can still share the same ID for purchasing in Settings>iTunes & App Stores); or
    On both phones go to Settings>Messages>Send & Receive and uncheck the email address(es) shown under "You can be reached by iMessage at".

  • Code golf: stop two while loops with guaranteed iteration ratio

    Proposal
    In the vein of the Perl tradition, I'd like to see if there's any interest in solving short programming puzzles in LabVIEW. Anyone can post a problem and define the rules for solving it.
    Here's a beginning/intermediate question to whet your "palette".
    Description
    With one user-action, how would you stop two while loops such that the ratio of their iterations is the always the same? One concrete way to visualize this situation is in taking measurements: two instruments use the same timing source to take measurements, but second divides the clock down so that it is an integer factor slower than the first. For example, if the slower instrument is four times slower, then at the end of the VI, if the slower instrument takes 100 measurements, the faster instrument has taken 400.
    Rules
    You may only use vi.lib
    You cannot include any other subVIs
    Your solution must pass for loop1 interval as low as 25 ms
    Template (attached in LabVIEW 2009)
    If folks are interested in this, then let's figure out how to make future problems better. Please post your suggestions and critiques, but only if you also post a submission ;-)
    Solved!
    Go to Solution.
    Attachments:
    Multirate Loop Code Golf.vi ‏11 KB

    Norbert_B wrote:
    a) You work with an integer factor of speed. While this matches many application areas, there are still cases where the factor has to be floating point (e.g. 2.5). Additionally, the factor might "invert", so the master loop runs slower than the slave (factor 0.5 for instance).
    It sounds like you're about to post another code golf question. If you think the problem scope is too small, you're welcome to fashion one to your taste. Thanks for volunteering :-D
    Norbert_B wrote:
    b) This example does not take into account that the hardware has to be synchronized with more accuracy than the software supplies (PXI?). If hardware synchronization is required, there are two possible ways:
    - The factor can be included in the synchronization (using PLL for instance)
    - The factor has to be software implemented by data reduction for the task running at the lower pace.
    Hrm, maybe puzzles aren't really your thing after all. You are correct: I did not define every constraint that can lead to a provable best closed-form solution, but that does not prevent people from stating their assumptions and forming creative, well-reasoned, and still correct designs. I overlooked this reading of the description and neglected to add a statement that said solvers were free to add their own conditions. I will do so in the fugure :-)
    If we choose the first of your suggestions, the VI must still retrieve the data at different rates. You can dedicate a loop for each instrument to decouple any jitter and latency introduced by their connectivity or internal operation; this adds some margin of safety when there is thread and driver contention. You can also implement a single counting loop like altenbach and forego the multiloop complexity.
    Norbert_B wrote:
    c) You don't state anything about "what happens with the data". Is this time consuming? Does it introduce additional delay in loop iterations? Is it OK to have data loss?
    I don't know -- you decide, you disclose, and you solve :-)
    In my specific situation, the measurements are time consuming and do add delay (each data "sample" is 5-20 megabytes), none can be lost, and the data must be available for others to analyze later. In addition, the amount of data is saturating the hard disk throughput. If a particular write takes too long, the instrument driver may overwrite a yet unfetched sample, which is unacceptable. I did not add these details to the problem discripton becuase they don't impact the puzzle.
    I don't want to burden people with my situation and ask them to solve my problem: I want to encourage them to bring their intuition and experience to a discussion. This is the design process at its heart: understanding why and how constraints affect your decisions. If a person states the additional conditions they've assumed, readers can learn why, and more importantly, when a Notifier might be more desirable than an Occurance or a Queue more robust than a Data Value Reference.
    The best NI-published advice for stopping multiple while loops (https://www.google.com/search?q=labview+stop+multiple+while+loops) is laughable (and is the "solution" in my template).
    Would you care to re-approach and contribute to this puzzle? I suspect you have a lot to offer :-)

  • I currently have one input but need to run two loops. I cannot get the two while loops to run so that they both pick up the same data, they are both picking up alternate samples. How can I get them to both pick up all of the values?

    The system I am trying to create calculates a number of values based on an input. I need to make the calculations and display the values for an entire production run and for each hour. The only way I know to do this is to create two while loops, one looking at all the values that are received and one looking only at the values for hour long periods.
    Any help would be great.
    Thanks
    RossH

    Why do you think that you have to have two loops to accomplish this task? Why not use one loop and accumulate the same data into two data sets based on the two sets of criteria?

  • How can I transfer data between two while loops in parallel

    Hello,
    I have two while loops in parallel and I want to transfer data from the first to the second loop. The problem isthat data are transfered only when the first loop ends. I tried with queue but it doesn't work. How can I do, preferentially without global variable ?
    Thanks.

    I join a very simplified VI's because the real works with PXI, RT, ...
    When you run the "secondVI.vi", no data comes in array from the "firstVI.vi".
    As I said in my first message, I tried with queue too but it doesn't work, because when the terminal go out from the while loop, while loop have to be ended to send data.
    Attachments:
    transfer_data.zip ‏20 KB

  • How to calculate the ratio between the maximum and minimum peaks of the two waves using two while loops?

    hello everyone,
    i'm rai from indonesia
    I have a final project about pulse oximetriy, I have some problems,
    how to calculate the ratio between the maximum and minimum peaks of the two waves using two while loops to calculate SpO2 ?
    My program image can be seen below predicament ?
    Attachments:
    spo2 akusisi data with filter lpf hpf smoot nilai max min ir merah.vi ‏249 KB

    Hi Rai,
    You should post this into the LabVIEW forum rather than Real-Time since this isn't a Real-Time application. Your post will see more replies in the LabVIEW forum. 
    As far as your question is concerned, you can write the max and min from the respective loops to a local variable to send the data out of the loops to a third loop or just do the calculation in one of the loops. This would be ideal if you're trying to do this while the loop is running. 
    -Jayk
    Applications Engineering
    National Instruments

  • How to make a button to stop and run a while loop?

    Hi all,
    I am a beginner in the Labview. I did a program that contains a while loop, its stop condition is connected to button. I selected “switch when pressed” to be the operation of this button. Our teacher asked us to make this button stops the loop if it is pressed and its name is converted to run instead of stop. And if it is pressed then again it starts the loop from the point it stopped in.
    Can anybody help me, please?

    First, please use a smaller font when composing your messages.
    You will need two while loops.  An inner loop which has its stop terminal attached to the stop button.  Put that in the False case of a case structure.  Wire a local variable of that stop button to the case selector of the case structure.  Put the case selector inside another while loop which is the one that keeps the program running no matter what the state of the original Stop button.  You will need a master stop button to stop the outer loop when you are ready to end the whole program.  Don't forget to put small millisecond waits in each of the loops so that the loops don't eat up all the CPU resources.
    For that stop button, you could rename the True title to Run, so that when it is pressed to stop the inner loop, the button will show the word Run.  Pressing it again pops it back out, allows the false case to execute and the innermost while loop to run.
    You could also change the words on the buttons by using property nodes.

  • Two while loops working in parallel at the same time

    Hello, how can I run a .vi with two while loops working in parallel at the same time? . I want that when I run a vi both can be activated o desactivate, but I can't get it. What can I do?
    Thanks a lot.
    Luz

    Here are some links for state machines.
    http://zone.ni.com/devzone/conceptd.nsf/webmain/c7​4cec177a289dbd86256c4e00600196
    http://zone.ni.com/devzone/conceptd.nsf/webmain/8C​4EECACF084F8E986256802007B9186
    http://sine.ni.com/nips/cds/view/p/lang/en/nid/137​47
    http://sine.ni.com/apps/utf8/niepd_web_display.dis​play_epd4?p_guid=B45EACE3DE6756A4E034080020E74861
    http://sine.ni.com/apps/utf8/niepd_web_display.dis​play_epd4?p_guid=B45EACE3E1E956A4E034080020E74861

  • How do i run two threads with different sleep times?

    How do i run two threads with different sleep times?
    Ive got thread A and thread B, they both update a jpanel.
    They both start when i press the start button.
    However thread A updates every 250ms and thread B updates every 1000ms. i cant just run them both at 250ms becuase this will mess it up.
    So for every four runs of thread A i want thread b to only be run once
    Does anyone know how to do this?
    Thanks, Ant...

    ok, ive done it but now i cant stop it!
    ive added buttons to start and stop, the start button works but the stop button doesnt. why doesnt "t.stop();" work?
        public void run() {
            while(t == Thread.currentThread()) {
                System.out.println("No " + t.getName());
                if (t.getName().equals("1")){
                    try {
                        t.sleep(1000); // in milliseconds
                    } catch (InterruptedException e) {}
                } else{
                    try {
                        t.sleep(250); // in milliseconds
                    } catch (InterruptedException e) {}
        }

  • How to out from infinite while loop in sub VI

    Dear Sir,
    how to out from infinite while loop in sub VI from main VI
    attached photo for solution but I can't understand it and i can't find the function in photo 
    please help
    Attachments:
    stop_subVI_frm_main.JPG ‏36 KB

    Asking how to get out of an infinite loop is like asking how to find the end of a circle. I'm not trying to be sarcastic but by definition, if there is a way out of the loop, then it is not infinite. I think what you are asking is how to avoid creating an infinite loop. Is there something about the suggestions you have been given that you do not like? My favorite suggestion is the notifier but maybe you just need an example. Turn on context help and read about the notifier functions in the code below.
    This is your top level VI
    And this is your subVI
    If this seems too complex then a global variable will work too. But what seems simpler can cause much more complex bugs. You can code fast and spend lots of time debugging or you can code slow and spend less time debugging. Personally I perfer writing productive code than looking for bugs any time.
    =====================
    LabVIEW 2012

  • How do I run two full screen applications on separate screens?

    I have two screens for my MacBook Pro with Lion; the laptop screen and a stock screen hooked up by a VGA cable. Currently, when I use a full screen application, my second screen just changes to the grey fabric pattern. How do I run a full-screen application on each screen?

    Hi Jared,
    Connect/turn on the external monitor. Open System Preferences on your MBP > Displays. There should be two windows, one for the external monitor and one for the MBP. Click on the window for the external monitor. Click on the Arrangement tab. Uncheck the box for Mirror Displays. This willallow you to set each display to its own resolution. On the external display, click on the pref window for the external monitor display setting. Click on Display. Set the resolution to what you want. On the MBP's display, click on the pref window for the MBP's display and set the resolution to whatever you want. You'll be in what's called "extended desktop mode." You'll have to move the "pointer" all the way to the edge of one display to get it to go onto the other display. Open whatever you want, and drag it to the extended monitor. Set it to full screen. Open another whatever on the MBP's display and set it to full screen. You should be full screen on both displays.

  • HT1347 How do I run two libraries from one computer?

    How do I run two libraries from one computer? One library is on the computer's hard drive, the second library is on an external hard drive. The computer that had the external hard drive crashed and I need to fix the iTunes library on it. How can I do this without corrupting the library on my internal hard drive?

    Launch iTunes with the Shift key held down and either create a new library or choose the one on the external drive. Any rented movies downloaded from another computer won't play.
    (81212)

  • How do i exit a while loop using event handler

    Hello,
    I have an event handler structure within which i run a while loop for a particular event. I would like to interrupt the execution of this while loop as soon as another event occurs, even if the while loop has not finished execution. I have tried so many ways, the best i could get is exiting one itteration after the new event occurs which is no good for me.
    Any suggestions???
    Thanks
    Me

    Instead of having a task while loop in an event case, put your task while loop in parallel with the loop surrounding the event structure. When the event which should start the task occurs, you can signal the start of the task while loop. You could use local variables of references to start/stop the loop when an event occurs. You could also use notifiers instead of variables to pass signals to start/stop the while loop. In general you should have a while loop for the event structure, and a parallel while loop to do the tasks. The parallel loop is controlled by variables or notifiers which are set in the event cases.
    - tbob
    Inventor of the WORM Global

  • Same applets running on 2 different browser independent of  each other

    Hi all,
    I am calling the same applet two times in a browser. So i declared all the variables to be shared by the 2 applets as "private static".
    Now i want the applets in 1 browser to be independent of the applets in another browser when multiple browsers are invoked.(remember that each browser has 2 applets each).
    In other words,same applets invoked in MULTIPLE BROWSERS should be independent of each other. How to go about doing that?
    Is it possible to somehow invoke separate jvms for 2 separate browsers on the same machine when clicked on the same link twice?
    Thanks in advance.

    Hi all,
    I am calling the same applet two times in a browser.
    . So i declared all the variables to be shared by the
    2 applets as "private static".
    Now i want the applets in 1 browser to be
    be independent of the applets in another browser when
    multiple browsers are invoked.(remember that each
    browser has 2 applets each).
    In other words,same applets
    r words,same applets invoked in MULTIPLE BROWSERS
    should be independent of each other. How to go about
    doing that?
    Is it possible to somehow invoke separate jvms for 2
    separate browsers on the same machine when clicked on
    the same link twice?To start a new JVM try System.exec("java someclass");
    Thanks in advance.(T)

Maybe you are looking for

  • Unable to update to iTunes 11.4 on Windows pc

    I have run iTunes on various Windows platforms for a number of years (for my iPod and iPad). Almost 2 years ago I bought a HP Pavilion Series 6 pc which ran on Windows 8 with no problems with iTunes about 2 months ago I received an update to iTunes 1

  • Inspection lot creation after receipt of certain quantities?

    Gurus, My user requires the creation of an inspection lot of 1 piece after the receipt of 200 pcs in stock as a kind of audit. This is not a goods receipt feom production as it will be done for each piece. .but was is needed is an event to create a l

  • URGENT HELP How Can I clone the database only?

    Hi all I have two database, oracle9.2.0.6 running on RHEL4 one is testing server and the other for the production server how can i clone the testing DATABSE on the productioin DATABASE? please help me urgent Thank You Regards

  • Newbie Question for the plug in

    Hey brothers, How can i connect a plug-in in logic pro 8? i want to use the sound from the plug in call first call horns? can anyone help me !? Thx for your opinion.

  • What's New Web Part will not show updates from Team Discussion Web Part

    I have a Team Discussion Web Part which I want to show in the "What's New" updates Web Part. I have indexed the "modified" column of the team discussion and added it as a target list for the What's new Web Part, however updates to the Team Discussion