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

Similar Messages

  • How to EXIT the while loop in Event response section?

    I'm writing a program to grab image using a NI card. The application uses the Event structure. When the GRAB button was pressed, it snaps image continually by putting the SNAP function in a while loop. Is there some way to exit the while loop?(Note :The while loop was put in the GRAB IMAGE event response section.)

    edit this event-case AND uncheck "lock front panel until the event case for this event completes".
    BTW, your thanks should go to Ankita, <a href='http://forums.ni.com/ni/board/message?board.id=170&message.id=151282'>here</a>
    cheers! 
    Message Edited by Dynamik on 11-13-2005 01:26 AM
    Message Edited by Dynamik on 11-13-2005 01:38 AM
    When they give imbeciles handicap-parking, I won't have so far to walk!
    Attachments:
    untitled.GIF ‏20 KB

  • How do I exit a while loop which has a 'read from spreadshee​t' pop up in it?

    I have a while loop which calls 'read from spreadsheet'. My problem is that after entering a filename the loop repeats too quickly for me to hit the end loop button. How do I exit the loop without adding a delay after the read thereby slowing the loop when I don't want to exit. If I select cancel I get 'error 43'. Is there a way to to use an error handler to prevent this from popping up and use it to end the loop?

    It's the error handler inside Read From Spreadsheet that creates the message. Specifically, one of the VIs called is Read Lines From File. The last VI in there is General Error Handler. You can delete it and save it with a different name. You should also modify it to return the error cluster. You'll also want to modify Read From Spreadsheet to return the error cluster so that you can trap the error in your VI. When cancel is selected, error code 43 is generated. Stop the loop when you see 43.

  • How do I correctly time while loops using SCPI and VISA/Ethernet communication to send DC current Values to a Power supply?

    I'm rather new to using labview and I having an
    issue with a test Data Aquisition lab I'm trying to setup using a
    Keithley 6221 AC/DC current source and a basic PCI M-series NI-DAQmx. 
    First of all, I'm looking to update the  current value on a power
    supply at a rate of atleast 10Hz and I'm using SCPI commands and VISA
    communication through ethernet to do so.  Attached below is the VI I
    have written. 
    The issue I'm having is this:
        My VI will
    loop through the values fine in software, or so it seems.  I am unable
    to get the Power supply to update sequentially if I don't set my loop
    delay to anything greater than 130ms.  If I try to run the loop faster
    it starts skipping values instead of counting 1,2,3,4,5,1,2,...etc.  it
    goes 1,2,4,5,2,4,1,2 on the display of the power supply and my DAQ unit
    also skips these values so I know that the number just isn't getting
    read to the Power supply in time.  I was wondering if this was due to
    my sloppy programming or if it is a hardware issue, my computer or the
    method of communication to the power supply?  Is this due to the fact
    that I'm using ethernet and VISA communication?  Is there a faster way
    to communicate or is GPIB faster?  Any input at all would be extremely
    helpful.
    On a side note:  Right now I'm using an pre-determined
    array of values that I can update on the fly but in the future this
    with be put into a  closed-loop control system.  The value for the
    power supply output will be determined by the loop and sent that way.
    Attachments:
    basic DC loop 6221 Keithley.vi ‏145 KB

    Also, one of the string constants is NOT set to '\' Codes Display. Here is an alternative method of calculating the index. I removed the DAQ and VISA stuff since I could not run it.
    Lynn
    Attachments:
    basic DC loop 6221 Keithley.2.vi ‏16 KB

  • 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 to stop a while loop of event structure from a main vi

    Hello;
    sorry for my english
    I have to stop a subvi from my main vi, the subvi contains a while loop and an event structure so I need to stop this loop while directly from my main vi I have tried global variable but it did not work
    any help please or example !!!   
    Solved!
    Go to Solution.
    Attachments:
    stop a while loop and event structure from main vi.png ‏16 KB

    IYED wrote:
    Hello;
    sorry for my english
    I have to stop a subvi from my main vi, the subvi contains a while loop and an event structure so I need to stop this loop while directly from my main vi I have tried global variable but it did not work
    any help please or example !!!   
    If this is an example of how your code looks, I'd clean it up before the developer who has to work on it next hits you over the head with his LabVIEW Style Book. 
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

  • How to stop execution in while loop without stopping execution of other loops in the same vi

    HI
    I am quite a novice in Labview.
    I have a problem in my project. I used a while loop inside my vi to build an array of ten values along with other loops. Then I used a stop button to stop manually the while loop. But it seems like the loop doesn't stop in the middle of the array building and so other loops in the vi doesn't work until the while loop finishes building the array and as soon as while loop execution is over, the complete vi stops. But all that I wanted was to build the array using the shift register along with the control to stop building array anytime. And not to stop execution of other structures when the while loop finishes.
    Can anyone help me?
    Rahul

    Hi Rahul,
    Modified ur Vi to work with single button.
    But the subtract case is not in any loop.
    So, once both the loops stop, the subtract case will execute only once. Depending on state of subtaract boolean at that time, corresponding case will be executed and the Vi will stop.
    so think of a logic where u can put this also in a new loop.
    Or you can also incorporate it in one of the two loops and pass the other loop's data to it.
    Let us know how you will proceed in this regard
    I am posting your VI as well a VI with my modifications VI in Labview 7.0 so that Thomas can give his suggestions too
    Plus, always keep a time delay in your while loops.
    Oh sorry, the "arrayinouttestnewfinal.vi" is the modified vi
    Regards
    Dev
    Message Edited by devchander on 01-10-2006 06:15 AM
    Message Edited by devchander on 01-10-2006 06:19 AM
    Attachments:
    arrayinouttestnewfinalnew4.vi ‏59 KB
    arrayinouttestnewfinal.vi ‏63 KB

  • How do i stop a while loop

    I'm new to labview and I'm having a problem stopping a while loop (running windows XP/2000 with the student edition of labview express 7).
    I'm doing a data acquisition program where I'm constantly reading in voltage and comparing it to a set point value, when the input voltage goes above the set point, i want the while loop to stop. How do I do this? I already have an LED going on when the criteria is met, but I'm not sure how to actually stop the loop (i.e. change the iteration value from true to false-i guess). If anyone can please assist me with this I would very much appreciate it.
    I've included my program too.
    Attachments:
    CO_Detection_Monitoring_System_Modified.vi ‏60 KB

    Hello Everyone-
    I've just posted a message about stopping a while loop and it was answered accurately and quickly- thanks to LV_Pro and PauloM- thanks much- its nice too see that there are many helpful people out there! Unfortunately, I have 2 more questions to ask of the forum.
    My application is almost completed- I just need to add an elapsed time counter that will tell me how long it took for my LED to trigger (from my set point-i.e. when from 0:00:00 until when my loop stopped).
    Now I've found a perfect elapsed time counter on the NI web site contributed from Mike Hall from Ohmeda Medical- the page is here.... http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=D37E2493DC333076E034080020E74861&p_node=DZ52032&p_source=external
    So my first question is, it looks like I can just extend the while loop box in my 'CO detector... .vi' and paste just the code from the 'elapsed time.vi' while loop into my loop and I will be set- but do I need to change my wait until next multiple to be a 1000 too in my program? Probably, but I'm not sure hence the question- or other ideas would appreciated.
    My second question is now that my application is complete (after I add the elapsed time above), I need to exactly duplicate this process for 7 other DAQ inputs (i.e. right now I'm using only 1 of 8 analog inputs on the FP-AI110). So should I make my 'CO detector.. .vi' a separate program (I remember reading something about this in one of the posts earlier).
    Any help is very appreciated.
    Thank you again,
    Daniel
    Attachments:
    CO_Detection_Monitoring_System_Modified.vi ‏60 KB

  • How can I make a while loop wait 10 seconds before iterations​?

    I am using labview to for an osmosis system that measures the amout of water lost from the reading on a scale.  
    I currently have the program displaying the data from 3 scales every second.
    I also need to calculate the flux through the membrane over time.
    I do this with a function that takes a change in the scale reading over time (with a shift register) followed by a series of mathematical conversions.
    The readings from the scale display OK every second, but I need to have at least 10 seconds between flux calculations.
    So my question is, how do I make a the shift register take one value from the scale, then wait 10 seconds before taking the second value?  That way I have the mass of water lost over a 10 msecond period.  
    Below is my current while loop for Flux using shift registers from data from 3 scales.  
    Any helkp would be great!
    Also, I'm new at LabVIEW...

    Bob_Schor wrote:
    Do you understand how Dataflow (a key idea behind LabVIEW) works?  If you put a Wait (ms) function (on the Timing Palette) with 10000 (10,000 milliseconds = 10 seconds) inside your While Loop, the principles of Data Flow will require all of the functions inside the While (specifically the Wait function) to finish their execution before the loop can run again.  As everything else in the loop takes approximately 0 seconds, this will make your loop run once every 10 seconds.
    Bob Schor
    I do not think that is a good idea. 
    The inner loop should be in sync with the outer loop, not run independent on it's own timer.
    If the inner loop is running independently you run the risk of using stale data.
    Actually  altenbach is right the inner loop does not need to be a for loop at all, but rather just a case like my suggestion (without the for loop) and the shift registers should be out on the main loop.
    My suggestion was a quick solution going by what little bit of the block diagram I could see, but if the entire code was posted I am sure we would see where more improvements could be made and possibly even a better solution.

  • How to stop While Loop in Event Structure with same button?

    Hello,
    I have a problem. I want to use one control to activate an event in a event structure, and the same control to terminate a while loop in that event.
    It is possible to use 2 controls to do this, but I need it to be only one.
    Thank you  
    Message Edited by Heinen on 02-19-2009 06:16 AM
    Message Edited by Heinen on 02-19-2009 06:20 AM
    The Enrichment Center is required to remind you that you will be baked, and then there will be cake.
    Solved!
    Go to Solution.

    Hello,
    I have a bit different problem.
    I have a tab control, with several buttons on different pages.
    In the current situation, we can talk about two pages, where one page ("Settings") in the Image, has a START and EXIT button, while second page ("Wait") has an EXIT button.
    In a while loop, I have event structure, which handles events of the START and EXIT buttons of the Settings page. This is fine. But I also want to control the Exit button of the Wait page.
    The control works like this:
    When I click on Start in the Settings page, the front panel shows Wait page and attempts to connect to a datasocket server on the remote computer. If the user wants to stop this process, he can click on Exit on Wait page too. But, this doesn't give any immediate effect. On the even of Start button, the front panel is not locked, so the user can actually click the Exit button on the next page when it's visible. But it's of no immediate effect. Means, what the LabVIEW does is, finishes the execution of event in Start button's click, and while this executes, it doesn't consider the Exit button's refreshed value (shown in Red circle in the block diagram).
    Simple question: Is there any way to check the updated (latest/live) value of a control during some event's execution? Or if I write an Event "Value Changed" for the Exit button and pass it to some variable. Is it the only solution?
    Thanks ahead.
    Vaibhav
    Attachments:
    terminate event_diagram.jpg ‏200 KB
    terminate event_front_1.jpg ‏63 KB
    terminate event_front_2.jpg ‏63 KB

  • 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

  • Stopping a while loop using the time difference of two tick counts

    Hi Guys,
    I'm currently writing a code which test how long does it take for a formula node to perform its operation. The program uses a while loop to perform the calculation, and the program stops after calculating when tick count has reached 10 seconds. The program then displays the number of iterations it does in 10 seconds. 
    So initially I created 2 frames of sequence structure. In my first frame I have my initial tick count, and in my second frame I have my final tick count and the while loop. I used the subtract function and divide the output by 1000 to get the time difference. Then using the comparison function, I set if output > 10 then the program should stop, to do this I linked the output of the comparison function to the stop button inside the while loop. 
    However, when I tried to run the code, the program just didn't run. Hence I created a similar program which puts the last tick count in new frame sequence. When I ran this code, the program never stopped. 
    Do you guys have any idea what went wrong with my codes.
    Thank you!
    Erry
    Solved!
    Go to Solution.
    Attachments:
    1. Tick Count.vi ‏27 KB
    tickcoun2.vi ‏27 KB

    Dataflow!
    In both VI's the stop terminal of the while loop is controlled by a boolean whose source is ouside of the while loop.  So that loop will either run once, or run forever, depending on the value of the boolean that is calculated before the loop starts and shows up at the tunnel going into the loop.
    I would recommend looking at the online LabVIEW tutorials
    LabVIEW Introduction Course - Three Hours
    LabVIEW Introduction Course - Six Hours

  • Question about while loop using Timer?

    I am trying to use a while loop to read data from oscilloscope through
    GPIB card continously(lasting for a fixed time, for example,1 minute). I
    want a Timer, when it expires, the while loop will stop. But I do not
    know how to implement it.
    Any help would be greatly appriciated!
    Thanks in advance.
    zhljh
    Sent via Deja.com http://www.deja.com/
    Before you buy.

    In article <87q5t2$7kh$[email protected]>, wrote:
    >I am trying to use a while loop to read data from oscilloscope through
    >GPIB card continously(lasting for a fixed time, for example,1 minute). I
    >want a Timer, when it expires, the while loop will stop. But I do not
    >know how to implement it.
    So, you need it to count down, then I assume? Okay, you need to put a
    true/false node within your for loop. Set the true case to i=1 (iteration
    of the for loop) so that it will initialize one time (and be true one
    time). Then, add whatever time you need for the vi to run to that
    indicator (where you send a numeric value on the first iteration). Put a
    greater than comparison to the timer and the additoin of the indicator and
    your value. Let that be the term
    inating thing on your for loop.
    Now, this might present a problem with a circular reference. If it does,
    you'll need to basically do the same thing, only you'll need to send the
    value through a shift register in the for loop.
    Harry

  • Event controll: How to stop a running while loop inside a event structure

    Hello,
    I have some problems with controlling a while loop inside a event structure (see attached VI).
    I habe 3 buttons ("Start Measurement, Stop Measurement, Quit Program"). When a measurement is running, it should be possible to stop the measurement by clicking on "Stop Measurement", but this does not work.
    Has anyone an idea?
    Thanks a lot and best regards,
    Michael
    Message Edited by MichaGue_01 on 04-23-2010 04:37 AM
    Solved!
    Go to Solution.
    Attachments:
    Event_Controll.vi ‏27 KB

    Hello,
    Try not to use while loops inside a Event structure.
    My approach is using two While loops (one will have only the Event structure).
    I had to use to Flag buttons that make it a bit more complicated but i am sure somebody will come up with a better idea, or you might want to have a think about it yourself.
    Have a look on the modified version on the attachment.
    Once you are happy how it works then you can Hide the 2 flag buttons from the Front Pannel by going to Block diagram right-click the indicators and choose option "Hide Indicators/Controls"
    I did it in LV 8.6 so i hope you can open it on your PC if not i can downgrade it.
    If you have any problem let us know.
    Regards
    Dimitrios
    Test Systems Computing Engineer
    Cummins Turbo-Technologies
    Attachments:
    Event_Controll[1]_modified.vi ‏18 KB

  • PDA While Loop using Bluetooth results in interface lockup

    The PDA Module ships with an example project that demonstrates client/server Bluetooth communication.  I decided to try it out with my PC acting as the server and my PDA as the client.  The demo basically transmits waveform data continuously via Bluetooth from server to client.  Attached is the code for the client PDA and the heart of the code is a while loop which continuously accepts data via Bluetooth and outputs the data onto the display.  For the most part, this is the stock example VI
    that ships but I had to modify the interface with an event structure so
    that I could use the PDA virtual keyboard to enter in the proper server
    address.
    The Bluetooth portion of the demo actually works great!  When the data set is set to random, the PDA very quickly displays new random data on the LCD.
    The problem occurs when I try to stop the VI.  Both the disconnect and Exit booleans are unresponsive when I tap their respective buttons.  My desired application will behave similarly to this demo which is why this is of concern to me.  Is there a better way to implement a continuous Bluetooth polling system but still retain the functionality of my front panel?
    System specifications:
    PDA Module 8.0.1
    iPAQ hx2790
    Windows Mobile 5.0.
    Attachments:
    NI PDA Bluetooth demo.JPG ‏106 KB

    Hi,
    Just by looking at the snapshot it is hard to tell what's going wrong. Since the bluetooth part is working fine, I would suggest that you try to strip the bluetooth part from your VI and run the VI in highlight execution mode. This should shed some light on what happens when you click on Stop or Exit buttons. If you still need help after that, please post your stripped VI here and someone from the community will be sure to help you out.  
    Regards,
    Ankita

Maybe you are looking for