Multiple while loops

I have two while loops in my application which run seperately. The program looks as follows
:   while loop 1           :       :  while loop2        :
I want to stop while loop 2 as soon as while loop 1 stops. I tried to connect the stop condition of while loop1 to the stop of while loop2, but the loop stops immediately after one iteration. How to go about it.
Regards,
Giridhar Rajan
Automation Engineer
Cruiser Controls
Mumbai, India

The big concept in LV is dataflow - a piece of code will execute when all its inputs are available. When you connected the two loops you caused a data dependency - the data in the wire coming out of loop one will only be available when the loop ends. So what happens is that you run loop 1 and when you stop it, the T value goes over to the second loop, which only starts running now. Since it gets T, it stops after one iteration. You can see this if you turn on Highlight Execution (the light bulb button). There are several ways to go around this - the simplest is a local variable - right click the stop button and select Create>>Local Variable. You can change this to be read and put it in the second loop. You will need to change the mechanical action of the button and make sure you set it back to false. A more advanced method is the event structure.
These are the basics in LV. To learn more, I suggest you read the LabVIEW user manual. Also, try searching this site and google for LabVIEW tutorials. Here and here are a couple you can start with. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide.
Try to take over the world!

Similar Messages

  • Stop multiple while loops in Vision Aquisition

    Hi,   I want to close multiple while loops with one stop button. I'm using the Vision Acquisition software for recording from multiple cameras and I want to close this recording from all cameras simultaneously. Since I'm knew to LABView I don't know how to do this. I'll include my VI here and maybe someone can help me.  Thanks!
    Solved!
    Go to Solution.
    Attachments:
    Aquire Images 2 with Cameras.vi ‏410 KB

    A local variable should be enough for your implementation. Look at the following article:
    Stopping Parallel While Loops in LabVIEW With One Stop Button
    Adnan Zafar
    Certified LabVIEW Architect
    Coleman Technologies

  • Starting stopping multiple while loops

    I have a rather large VI that runs multiple while loops with case strutures inside.
    I would like to be able to shut off and on the while loops programmatically depending on events.(cycle complete or cycle started)
    I need to store my measured data in a table but everytime I shut off the while loop  the data I gathered is lost.
    So it goes like this- measure analog voltage-put it in a numeric indicator...now I want to put in a table only once per cycle of my machine.
    If the opeator pushes the reset button the table is available for a report generation acquisition.
    Any help would be appreciated.
    Thanks
    Solved!
    Go to Solution.

    Do you want something like this?
    Attachments:
    Loop_Control_Multi.vi ‏109 KB
    Loop_Control_Multi_Demo.vi ‏177 KB

  • Multiple DAQ Cards, Multiple While Loops

    I'm writing a code to support 3 small test stands that each have the same outputs and inputs as the others. I'm running them all off of an 8-slot DAQ. Each test stand has its own dedicated RTD Card and Analog Out card, but they all share a 32-channel Analog Input card.
    I'd like to decouple the 3 test stands as much as possible - if I have to take out an RTD card or Analog Output card, I don't want the entire LabVIEW program to stop running. I want to be able to keep running and logging data on the other two test stands if I were working on the other test stand. Is there a way to do this with only 1 cDAQ? Is it simply a matter of creating separate, independent while loops for each test stand? If so, would LabVIEW have issues with each while loop writing its own measurement file in parallel with the others?
    Thank You.

    Is it safe to assume you've been running the three tests?  Some of your post makes it sound like you've run them coupled while other parts make it sound like you haven't successfully had all three tests running simultaneously.
    If you aren't running them, are you using hardware timing (counters) for your tasks?  If you're looking to use counters, you're only using one per task, correct?  The cDAQ will only have four counters total to be shared between your loops.
    I can't remember off the top of my head if it is the task or the computer that reserves a cDAQ chassis.  I want to say it's the computer so you can run multiple tasks from the same cDAQ.  But, you'd still need to choose ctr0, ctr1, ctr2, etc in each task so that you don't share these resources between tasks.
    Are you looking to pull the shared module out frequently?  If not, are you gaining enough functionality to justify buying two redundant modules to gain decoupling?

  • How to use one single boolean button to control a multiple while loops?

    I've posted the attached file and you will see that it doesn't let me use local variable for stop button, but I need to stop all the action whenever I want but more than one single button on the front panel would look ugly... The file represents the Numeric Mode of
    HP 5371A. thanks for your time
    Attachments:
    NUMERIC.vi ‏580 KB

    In order to use a local variable, you can change the mechanical action of stop button (Switch When Pressed will work), or create a property node for it and select values. You'll also have to do a lot of work changing those for loops into while loops so that you can abort them.

  • Multiple While Loops Write to One File

    Hello,
    I have three different instruments from which I am sampling, each at a
    different sampling rate.  Each instrument is being sampled in its
    own While loop.  How do I write all the samples I collect to a
    single text file?  I would like something in the following format:
    [Timestamp] [Instrument 1's First Sample] [Instrument 2's First Sample] [Instrument 3's First Sample]
    [Timestamp] [Instrument 1's Second Sample] [Instrument 2's Second Sample] [Instrument 3's Second Sample]
    ...and so on..
    Thank you,
    Olyvia

    ofro wrote:
    I have three different instruments from which I am sampling, each at a different sampling rate.  Each instrument is being sampled in its own While loop.  How do I write all the samples I collect to a single text file?  I would like something in the following format:
    [Timestamp] [Instrument 1's First Sample] [Instrument 2's First Sample] [Instrument 3's First Sample]
    [Timestamp] [Instrument 1's Second Sample] [Instrument 2's Second Sample] [Instrument 3's Second Sample]
    ...and so on..
    This seems like a flawed project.
    If each loop samples at a different rate, the samples will arrive at different times. Typically there won't be a single timestamp for all three samples. Can you explain what you actually want to write to the file from each loop?
    Do you want to write to the file incrementally inside each loop, or do you want to write everything at once after all loops have finished?
    LabVIEW Champion . Do more with less code and in less time .

  • How do you prevent display glitches with multiple while loops.

    I would like to use 2 while loops, 1 for displaying elapsed time and the other for executing a sequence of initialization steps. Every time the sequence transistions from one frame to the next, I get a glitch in the elapsed time display. How can this be avoided? Should I be going about this in a different way?
    Attachments:
    timeTest.vi ‏265 KB

    I would drop the whole semaphore thing and hold the cluster in a functional global (also called a shift register database or LV2-style global, you can find info on the concept here). Add methods to update different parts of the cluster. Much easier code and the required protection of the cluster is there.
    MTO

  • 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 :-)

  • Labview Crashes when I try to close my while loops

    Hi
    I have written a LV Vi  for  simultaneously  aquiring a
    video stream from 4  Fire Wire cameras. In this vi I use multiple
    while loops(running parallel).
    Nearly every time I try to stop the VI labView crashes and doesn't respond at all.
    The only chance to stop LV is to close it with the task manager.
    I'm using LV 8.2.
    Has anybody got an idea.
    Thanks a lot
    Matthias

    Hi Mathias,
    this behaviour I experienced often when using large amounts of memory by creating large arrays (with many copies). Another proplem is to create references without closing them, this consumes windows ressources. While the VI runs, is there an increasing use of memory in the task manager?
    When the VI tries to stop, are you able to switch to the block diagram? Then you could activate the highlight mode (debugging) and LV shows, which node is still working with the green arrow at the node.
    Just a few ideas...
    Greets, Dave
    Greets, Dave

  • Multiple event structure in a while loop

    Dear All,
                   I had a multiple event structure inside a while loop. The purpose of doing so is because I had a few 2D picture on the front panel. I would like to detect which 2D pictures had been click using the mouse down event structure for 8 of my 2D pictures.
                  The problem that I faced now is that when I of the event case or one of the 2D pictures had been click, it will not exit the while loop. I had to click on all the 8 2D pictures before it will exit the loop.
                  I had uncheck the under the "Edit Event" --> "Lock Front Panel (defer processing of user action) until this event case completes". But I am still stuck inside the loop.
                  Each 2D picture will perform different action therefore I cannot have an event case of all 2D pictures inside else I would know which 2D picture had been click.
                 Is there any other way out of this situation? Pls help. Thanks a lot

    A producer/consumer architecture (look at the examples that ship with LabVIEW) is comprised of two parallel while loops. One loop contains the event structure. The other contains your consumer which is basically a queued state machine. It receives messages from the producer via a queue. Your event structure can register a separate event for each 2D picture control or it can use a single event that would determine which spefic controls was clicked on. This is a more general approach and expands easily. Here is a basic example of what I am talking about.
    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
    Attachments:
    Event Producer-Consumer.vi ‏14 KB

  • When I add a while loop to the vi "niScope EX Multi-Device Configured Acquisition (TClk)" to acquire data for multiple times, it works but it runs very slowly.

    Because I want to acquire the similar data for multiple times and then take an average to increase SNR, I add a while loop to the vi "niScope EX Multi-Device Configured Acquisition (TClk)".  It works but it runs very slowly (about 1 sec for each iteration). I think I had put the while loop at a wrong position, which makes the vi run from the very beginning in each iteration. So I really want to know where should I put the while loop to improve the speed? I have attached all the vi and subvi.
    Thanks very much.
    Attachments:
    Multi-Device External Clocking (TClk).vi ‏1166 KB
    avgWfm.vi ‏15 KB

    Dear Zainykhas,
    Thank you for posting this to the discussion forums and for uploading some sample code.  I took a lok at the issue you have been having, and it is unclear to me as to why you have placed two for loops around the original while loop.  My understanding is that you want to use the original Sample.vi and want to execute this N times where N is the Max Freq divided by Interval so that you can scan for a range of frequencies.
    Why not just put Sample.vi around one for loop and use the increment counter scaled by the interval to count up towards Max Freq and insert the desired Frequency into the cluster using Bundle By Name?
    Kind Regards,
    Robert Ward
    Applications Engineer, NI
    Attachments:
    Modified - RW.vi ‏48 KB

  • How do you plot multiple curves on the same graph when using a while loop?

    I am writing a program that will plot the IV Output chracterisitcs curves for a MOSFET transistor. I have two sweep variables Vg and Vd. For each Vg valve selected, Vd is swept from its start to stop voltage creating a graph for that Vg valve. Both of the sweeps are done using while loops. Ideally I would like to display all of the Vg plots on the same graph while having the ability to do real-time graphing. Can anyone help me figure this problem out? I have attached my program. Thanks!!
    Tammy
    Attachments:
    outputfin2.vi ‏165 KB

    Hi Tammy & Tica T,
    As far as I see it - this thread is a very bad version of already existing bad version......
    http://forums.ni.com/ni/board/message?board.id=170&message.id=127857
    I expected, that an Applications Engineer from NI knows something about  a Transistor and how an Output characteristic looks like !!  Take a look to a typical Transistor Datasheet ( e.g. n-channel MOSFET) - you will see, that there is no relation of ID vs Time like in your example ( values vs time )  but  IDrain vs VDrain at different VGate's ( no relation to Mr. Bill Gates ).
    Find attached a vi, that in general does what you need - drawing of  curves vs x-axis (XY-graph in use)  - in test_sweep.zip.  And that you geet an impression, how it might be done ...... dynamic Output characteristic of a Transistor with Standard Equipment of a Lab ( Scope + Generator + Power Supply ) find in addition a Frontpanel - picture. One of the interesting points here is - the self-heating effect; visible on ch3 of scope - 5µs Pulse is already a very long time...... This measurement was done in order to compare with our own Transistors......... 
    Hope this helps a little bit to understand, what we are talking about.
    Regards
    Werner
    Attachments:
    test_sweep.zip ‏358 KB
    dynamic Transistor char.png ‏65 KB

  • Multiple instances of identical vi inside a while loop

    We have a while loop that is monitoring 6 sensors in a heated water bath.
    Each sensor has the same basic switching parameters.
    While the loop runs, it does not tie the shift register value to the same instance every time it runs.
    The 6 instances of the Switch Pass or Fail.vi in the attached project have a dummy 1, 2, 3, 4, 5, 6 value and we don't know how to tell the main program which instnace to run when a switch switches.....
    So far, everything else works, but we can't get the Switch Pass or Fail.vi to run the same way twice...
    Attachments:
    switch pass or fail vi question Oct 17 2011.zip ‏575 KB

    Stepping back to our "inception" problem.. we have a problem, within a problem, within a problem...
    Before we can answer our other problems, we need to be able to test our VI and can't figure out how to update a bank of shift registers, one at a time, without having the wires break when we don't update each output from the case structure on each case.  The VI won't let us run by populating one output from a wire to different shift registers in a "bundle" vi.
    The goal of the attached VI is to have "TMP Reg" input, initial, shift register, values into the "switch pass or fail.vi" and have the output on the "trip temp out" wire update only the shift register in the "bundle" associated with that switch.
    example: the first case structure entry "1" would output the "trip temp out" value to the first entry in the bundle to update the first shift register.  Then, when the second case ran, it would update the second entry in the bundle to update the second shift register, and so on, until all six cases (switches) had thier shift register values updated.
    Attachments:
    cycle through updating shift registers without re-writing the others.png ‏148 KB
    clusters now feed the RGTR_FX.png ‏195 KB

  • Why writes LabVIEW only every 2 seconds the measured Value to a Excel (In a while loop with 100 ms tact)?

    Hi everybody,
    I use the myDAQ to measure speed, ampere, and voltage of a battery driven motor. (For Current measurement, i use a Sensor which outputs a 0-10 V signal). I placed all DAQ-Assitants in a while loop with a [Wait until next ms multiple] clock and set a value of 100 ms. I thougt, Labview will now write into my text file 10 times a second all values. In fact, as you can see in the attached text file, Labview only writes in a unsteady interval of 1-2 seconds a value, which is too less.
    The question: Did I do anything wrong, how can you create VI that writes you lets say 10 values a second into text file? Or is simply the DigitalMultimeter input of the myDAQ not able to sample a rate of 10 Hz? I couldn´t find any information in the specification handbook about the sample rate of the DMM?
    If anyone can help me would be great! Thanx a lot, Markus
    Attachments:
    Measure Speed+Current+Voltage into Excel.vi ‏175 KB
    Test7.txt ‏1 KB

    File I/O is not very efficient. I recommend that you do you file logging in a parallel task. Have one task do your data acquision. This task would then pass the data to be logged to the logging task via a queue. That way your file operations do not impact your data acquision. Also, express VIs are not very efficient. You would be better off accessing that directly using the DAQ VIs. The express VIs contain lots of steps that do not need to be done every time you call it such as initializing the device.
    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

  • While loop and data acquisition timing worries

    Hello everyone, 
    I apologize in advance if this is a silly question, but I could not find the answer around here. 
    I have made a VI to record continuously from 64 analog channels at a 5kHz sampling rate. I then stream this data to a tdms file. The data acquisition and write functions are in a while loop. 
    I the same loop, I have a bunch of other loops, that each run on their own wait timers to help limit the amount of memory they take up. I am now worried that this may somehow affect my data acquisition timing.
    If I put a bunch of timed loops within another loop, does the outer loop run at the same pace as the slowest of the inner loops? And could that mess up my sampling rate?
    I have attached my VI, in case what I just wrote makes no sense at all. 
    Thanks for any tips...
    Attachments:
    Record_M8viaDAQv3.vi ‏237 KB

    Well, looking at your code you will only write to your TDMS file one time. You have multiple infinite loops within the main/outer loop. That means that the main loop will only run a single iteration because it cannot complete an iteration until all code within it completes. With at least two infinite loops inside the loop it will never complete. Not too mention the only way to stop your code is to hit the stop/abort button. NOt a very good way to stop your code. As someone once said using the abort to stop your code is like using a tree to stop your car. It will work but not advised.
    As Ben mentioned try to understand data flow better. You have unnecessary sequence frames in your code where normal data flow will control the execution sequence.
    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

Maybe you are looking for

  • Acrobat Pro 10.1 pushes CPU to 100% during scanning.

    Hello all, I am deciding if I want to upgrade to Acrobat Pro X.  I have installed the trial version on a test system.  It is Windows 7 Ultimate with 4 GB Ram, 1 CPU.  I let the software update to 10.1 before doing anything. System sits between 0 and

  • Call tarnsaction using set paremeter

    Hi all,          i have to use the below code that when i click on vbap-vbeln then it shuld show me va03 transaction. i m getting that but when i click on vbap-posnr also its going to va03 transaction so i want to restrict it to only wa_vbap-vbeln. p

  • How to shrink text in SAPScript

    I am working on a legal form in which one of the line contains arround 120 characters. All the 120 characters are to be printed in the same line. I am not able to get all the characters in same line using font TIMES 6,00. Is there a way to shrink tex

  • Upgrading from osx 10.5.8 on an older Intel dual core duo macbook?

    I have a 2.4 ghz intel core duo macbook with 2GB of 667 mhz ddr2  sdram. I am running osx 10.5.8. Can I upgrade to a higher os version? If so which can I upgrade to? Do I need to go through any interim steps or can I go directly to the latest osx ver

  • 1.01.03 vs 2.11

    I am not trying to beat a dead horse here, but can anyone tell me which I should go with the original firmware or should I upgrade? I cannot make up my mind. I have always used Music Match previously and right now I can no longer use it with .0. Howe