Control a while loop in the sub vi using a button in the main vi?

Dear all,
  I want to be able to control ( turn on or off) a while loop in the sub vi from a button control in the main vi. How can I use the Control Reference to achieve it?
  Thank you in advance. 

Like this
look at attached vi's
Run the main vi
Attachments:
main_boolean.vi ‏12 KB
sub_boolean.vi ‏16 KB

Similar Messages

  • Controlling a while loop

    I have 2 parallel while loops. The main will run all the time. The
    slave loop I need to turn on and off at will. Can someone present a
    simple exampl have how to do this?
    Thank You

    There are a number of ways to do this.  I think two of the simplest are in the attached image.  If you want to make your code a little more robust, I'd use queue's instead of local variables, so as to prevent race conditions and have your code a little more deterministic.  If you do go the local variable route, make sure the mechanical action of the control itself is one of the switching ones, because if the action is latching, LabVIEW might not catch it (which speaks to the non-determinism of locals).
    Hope this helps.
    Message Edited by Day on 09-26-2006 01:56 PM
    Attachments:
    Loops.jpg ‏41 KB

  • My daq 6008 wil not drop the 5V after the VI is stopped, i have a digital signal going from the error out on the daq in the while loop to the error in on the daq outside the while loop and a boolean going to the data of the daq outside

    my daq 6008 wil not drop the 5V on a digital output after the VI is stopped, i have a digital signal going from the error out on the daq in the while loop to the error in on the daq outside the while loop and a boolean going to the data of the daq outside, but i can t seemto get it to work

    i attached the block diagram so you can have a look
    Attachments:
    PID Temp control.docx ‏120 KB

  • How to create a time control for while loop?

    Hello all,
    I would like to control my while loop's execution time. In other words I want to stop while loop's execution after time (in ms) which is set by user. For example user sets 5 seconds to front panel control and a while loop runs and stops after 5 seconds.
    I am not sure is it possible with the while loop. I succeed with the timed loop but it suits badly to my application. Is there any other loops for timed control if it is not possible with while loop? There is also a simple while loop with Random Number (0-1).vi as attachment.
    Best Regards,
    Jick
    Solved!
    Go to Solution.
    Attachments:
    execution time loop.vi ‏6 KB

    hi,
    see this, may be it will help.
    Best luck
    Gaurav k
    Gaurav k
    CLD Certified !!!!!
    Do not forget to Mark solution and to give Kudo if problem is solved.
    Attachments:
    execution time loop.vi ‏9 KB

  • How to run a do-while loop on the 2nd execution after a stop on failure occurs?

    I am trying to use the Stop on Failure process model callback from the TestStand Examples.
    If a step fails within a Do-While loop and the test is terminated, the second time the test is run (continuing to the Next UUT in the process model), the condition for the do-while loop is checked first before it ever enters the loop. This is incorrect because the Do-While loop should execute once and then check the "while" condition.
    Also, If I was to stop the execution altogether and then restart the test (instead of continuing with the Next UUT), it runs the loop once, then checks the "while" condition.
    I'm not sure if I am describing this clearly enough. The execution seems to flow like this:
    Start test
    Do
    NumericTest step FAILS  -> terminate
    Next UUT starts
    While (condition is false and skips over Numeric Test step).
    So it seems that TestStand thinks it's still within that Do-While loop on the second execution and whatever runtime variables are not reset correctly.
    Is this a TestStand bug?  It happens in both TestStand 3.1 and 3.5.
    Is there any way around this?
    Thanks for any help.

    If it is what I think it is, it is a bug. Try unchecking Sequence Properties>>Optimize Non-Reentrant Calls to This Sequence and please tell me if that fixes it.

  • How to code a parallel 'for loop' and 'while loop' where the while loop cannot terminate until the for loop has finished?? (queues also present)

    I've attached a sample VI that I just cannot figure out how to get working the way that I want.  I've labeled the some sections with black-on-yellow text boxes for clarity during the description that follows in the next few sentences.  Here's what I want:
    1) overall -- i'm intend for this to be a subVI that will do data acquisition and write the data to a file.  I want it to use a producer/consumer approach.  The producer construct is the 'parallel for loop' that runs an exact number of times depending on user input (which will come from the mainVI that is not included).  For now I've wired a 1-D array w/ 2 elements as a test case.  During the producer loop, the data is acquired and put into a queue to be delt with in the consumer loop (for now, i just add a random number to the queue).
    2) the consumer construct is the 'parallel while loop'.  It will dequeue elements and write them to a file.  I want this to keep running continuously and parallel until two conditions are met.
          i. the for loop has finished execution
          ii. the queue is empty.
       when the conditions are met, the while loop will exit, close the queue, and the subVI will finish. (and return stuff to mainVI that i can deal with on my own)
    Here's the problems.
    1)  in the "parallel for loop" I have a flat sequence structure.. I haven't had time to incorporate some data dependency into these two sequential sections, but basically, I just care that the "inner while loop" condition is met before the data is collected and queued.  I think I can do this on my own, but if you have suggestions, I'm interested.
    2)  I can easily get the outer for and while loops to run sequentially, but I want them to run in parallel.  My reasoning for this is that that I anticipate the two tasks taking very different amounts of time. .. basically, I want the while loop to just keep polling the queue to get everything out of it (or I suppose I could somehow use notifiers - suggestions welcome)...  the thing is, this loop will probably run faster than the for loop, so just checking to see that the queue is empty will not work... I need to meet the additional condition that nothing else will be placed in the queue - and this condition is met when the for loop is complete. basically, I just can't figure out how to do this.
    3) for now, I've placed a simple stop button in the 'parallel while loop', but I must be missing something fundamental here, because the stop button is totally unresponsive.  i.e. - when I press it, it stays depressed, and nothing happens.
    suggestions are totally welcome!
    thanks,
    -Z
    Attachments:
    daq01v1.vi ‏59 KB

    I'd actually like to add a little more, since I thought about it a bit and I'm still not quite certain I understand the sequence of events...
    altenbach wrote:
    zskillz wrote:
    So i read a bit more about the 'dequeue element' function, and as I understand it, since there is no timeout wired to the dequeue element function, it will wait forever, thus the race condition I suggested above can never happen!
    Yes, you got it!
    As I've thought about it a bit more, there's a few things that surprise me... first, the reason the 'dequeue element while loop' errors is not because there's nothing in the queue, it's becaues the queue has been released and it's trying to access that released queue...   However the problem I have is this --- Even though there's no timeout wired to the dequeue element, I still would think that the while loop that contains it would continue to run at whatever pace it wanted -- and as i said before.. most of the time, it would find that there is nothing to dequeue, but once in a while, something is there.  however, it seems that this loop only runs when something has been enqueued.  the reason I say this is illustrated in the next code sample MODv2 that's attached below.  I've added a stop button to the "queue size while loop" so the program runs until that is pressed.  I've also added a simple conditional in the "dequeue while loop"  that generates a random number if it a button is pressed... but this button is totally non-responsive... which means to me that the "dequeue while loop" isn't actually continuously running, but only when an element is added to the queue.  this still seems almost like the 'dequeue while loop" waits for a notifier from the queue telling it to run.  can you explain this to me? because it is different from what I expect to be happening.
    rasputin wrote:
    I tried to open your VIs but it doesn't work. LV
    is launched, the dialog box (new, open, configure...) opens and then...
    nothing. Not even an error message. I guess it isn't a problem of LV
    version or a dialog box would appear saying this. Could you, please,
    send a image of the code?
    Thanks,
    Hi Rasputin, I'm using LV8.  I assume that was your problem, but who knows.  I've attached a pic of of altenbach's solution since it's what I needed.
    thanks
    -Z
    Message Edited by zskillz on 10-20-2006 11:49 AM
    Attachments:
    daq01v1MODv2.vi ‏63 KB
    daq01v1MODpic.JPG ‏116 KB

  • How to pass a value from inside a while loop outside the loop

    Hello to everybody, I have been searching through the forum but I have not found a certain answer for my problem. I would try to explain my problem as breefly as posible:
    I have to send by a BNC2120 two signals and acquire an other one thats comes from a preassure sensor. That part is done by introducing simulating and acquiring DAQmx inside while loops.It is sycronized by my self, proving such diferent values (is not the optimum, but is only the first prototype) and works as I expected. Well, then I want to sample some of the values of these signals, that is done with relays and local variables to get the value in the instant I want to sample. Here begin my problems: I want to extract the sample values out of the while loops without restarting them, I mean: I do not want to stop the while loops because the acquisition and the generation of the signal must be continuous, but I do not know if it is posible to put the while loops in "standby" until I operate with the values I have sampled and then the signal generator and the acquiere continues from when it has stoped before. Particulary I want to obtain the value of the top while loop (inside a case) when the counter arrives at 15.
    I have proved to do with local variables, global variables, making a state machine, with event cases, with flat secuences...I have been reading about and proving diferent posible solutions for this week and the whole past week and I have not found the solution.
    If any of you know how I can do this thing, I would be loved to listen your opinions. My proyect is above: 
    Thank you a lot in advance.
    Sinceresly,
    Miguel.
    Attachments:
    maq_estados_event_case.vi ‏239 KB

    It definately sounds like what you really want is a Producer/Consumer.  It is an architecture that uses Queues to pass data from a data generation loop (producter, your DAQ loop) and a data processor (consumer).
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • 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

  • Can't get sub vi to process button pushed in main vi.

    I'm trying to control whether or not data will be written to a spreadsheet through the use of buttons on my main panel. I have 5 sets of data and want to be able to tell the program when to save them by pressing a button. To do this, I created 5 sub vi's with the data as the inputs and a boolean control input representing the button. I then created a case structure inside a while loop, displaying nothing when the boolean is true (so the while loop just loops over and over again doing nothing when true) and saving it to a file when it is false, i.e. when button is released. for some reason, even though i wired the button to the appropriate terminal on the sub vi, when i release the button in the main vi, nothing
    happens. the loop in the sub vi seems to always read the boolean as true, not comprehending my action in the main vi. However, if I release the button directly on the panel of the sub vi, it comprehends immediately and displays a dialog box for saving. any suggestions?
    thanks a ton
    yusif

    Hello Kim,
    I'm attaching my main vi along with 2 of the sub vi's i want to use within it. As you can see in the main diagram, there are 5 while loops that I want to place in sub vi's, but can't because of the problem I described earlier. I tried the global variable approach with no luck, perhaps I'm not implementing it properly though.
    i look forward to your response
    thanks again...
    -yusif
    Attachments:
    Plot_Intermediate_Vars.vi ‏444 KB
    Write_All_SUBVI.vi ‏91 KB
    Write_Z_SUBVI.vi ‏44 KB

  • How to get the loop sequence time (i) out of the while loop in the sub-vi to the main vi?

    I tried to search for the answer but no much luck.  My situation is that I used a sub-vi containing a while loop in my main vi. Now I need to see the while loop sequence number (i) from that sub-vi in my main vi.  In the sub-vi I have the indicator to show this loop sequence flawlessly, but that's inside the loop itself.  If I use this indicator as a terminal in the sub-vi, I can only see the last sequence number in the main vi after the loop finished its execution.
    Is there a way to accomplish this? Thanks.

    Hi nobody,
    well easiest (but error prone) way is to use globals to move data from subvi to main vi. You can also give the reference of the main vi indicator to the subvi to write to a "value" property node. You can also use queues, and there are other techniques too
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Waveform charts slowed down control system while loop

    Hi
    In my application, I have control system which i acquire data, process and output the result. I placed some waveform charts in the while loop where i acquire data, process and output. This made while loop to miss data points( late). Is this because waveform charts store data as time passes?

    Waveform charts store data in a history buffer of configurable size. You can change it to a smaller number.
    What is the size of the history buffer?
    How many charts are you updating in your loop?
    What else is happening in your loop?
    How are you updating them (wire, local variable, value property, etc).
    How fast is your loop rate?
    Are your plots simple (thin lines) or fancy (e.g. large dots and thick lines)?
    Is autoscaling on or off?
    Are the charts set to "synchronous display" by accident?
    How many traces are on your chart?
    What is your LabVIEW version?
    What is your OS?
    Do you have overlapping elements on the front panel?
    Could you attach a simplified version of your code so we have a better idea what you're actually doing?
    LabVIEW Champion . Do more with less code and in less time .

  • Writing a file for prescribed amount of time in a while loop after the triggering condition is met

    Hello Guys,
    I am trying to program an application in which if the trigger condition is met it should start to write the file.
    I was able to do that, but if I want it to be written for certain amount of time, and once the trigger condition is met, it should continue to write the files for prescribed amount of time. I was not able to do this. The file name should also be updated accordingly.
    I tried to with some options by keeping the creation of the file outside of the loop, if I do that then if the trigger condition is not met it will stop writing and I dont want that, as once the trigger condition is met it should be true thereafter.
    So I cant keep any thing outside the while loop, bcaz then it checks the condition of the shift register for the trigger and I have it as a false constant.
    I am attaching my application which is kind of mess and I have written in the application where I am having problems. For every iteration of while loop it makes a new file, and i dont want that, I want to write specific amount of time data to the each file.
    Please take a look at my code and help me in solving the problem. Any insights and examples on how to do this thing will be a relief to me.
    Thanks in advance.
    Regards,
    Nitin
    Attachments:
    PXI_4462_Sync_and_Stream_trigger.zip ‏192 KB

    what i am saying is to keep track of how much data you have written and whenever you need to make a new file you make 1.
    here is a vi that i just made that should show you. let me know if you need any help understanding it.
    Attachments:
    new file exemple.vi.zip ‏21 KB

  • Stopping a while-loop in a sub-vi

    Hello,
    I want to stop a while loop that runs in a sub-vi. It does not work with a local variable, is there a possibility to implement this without using global variables?
    Many thanks !

    One way is to use a notifier.
    See attached - Uses LV 7.1.Message Edited by NeilR on 05-04-2005 08:10 AM
    Attachments:
    stop2.zip ‏14 KB

  • To count the number of while loops, do you just have to attach a DBL indicator to the little i box in the while loop of the program?

    I have just followed an example in a book to count while loops and was just want to make sure I havent missed something simple. My program is attached
    Solved!
    Go to Solution.
    Attachments:
    second attempt.vi ‏45 KB

    Hi Ssteel,
    Just some additional observations/tips on your code...
    1. I notice that you have a standard stop button going into a "run if true" stop condition of the while loop. In this cercumstance it is common to have the stop condition set as "stop if true". You can change this by right clicking the stop terminal and enabling the "stop if true" property. Obviously, it somewhat depends on your design preferences.
    2. If you have any issues with the application, perhaps you notice that it is taking over your processor resources, you should add some execution timing into the while loop. You will find the timing functions in the block diagrams functions palette (programming > timing). The Wait (or "wait until next ms") functions will provide your application with "down time", which means that the processor can execute other tasks.
    3. To elaborate what MikeS81 correctly stated, insert an incriment before the numeric indicator as shown below to get the actual number of cycles (i.e. the count terminal of the "while" and "for" loops are 0 indexed). Also note that I have changed the representation of the count to interger (blue). You do not need floating point precion when displaying the inciment count, at a while loop can only execute a "whole number" of times.
    I hope this has been useful to you Ssteel.
    Thanks for your post,
    Rich R
    Applications Engineer
    National Instruments UK & Ireland

  • How to stop a second while loop when the condition in the first one is met for different VIs

    Hi, am running two seperate Vi's. am new to labview so please help accordingly.
    I have introduced a comparison test  in one Vi through ashift register. i would like now the second Vi to stop when this comparison condition in the first Vi is met. 
    I dont want the first Vi to stop, it should only stop the second Vi while awaiting for the next input.
    waiting for your help guys

    Thanks so much guys. am now starting to pick some ideas. i have attached the Vis as requested for best identification of the help.
    waiting help guys
    best regards
    Alex
    Attachments:
    first Vi.vi ‏132 KB
    second vi.vi ‏149 KB

Maybe you are looking for