Simple example - Break FOR loop inside an event structure based on Front panel event change.

I am running a for loop inside a state machine architecture that contains a FOR loop. How can I break this For loop based on Event change in front panel ??
Abhilash S Nair
Research Assistant @ Photonic Devices and Systems lab
[ LabView professional Development System - Version 11.0 - 32-bit ]
LabView Gear:
1. NI PXI-7951R & NI 5761
2. The Imaging Source USB 3.0 monochrome camera with trigger : DMK 23UM021
OPERATING SYSTEM - [ MS windows 7 Home Premium 64-bit SP-1 ]
CPU - [Intel Core i7-2600 CPU @ 3.40Ghz ]
MEMORY - [ 16.0 GB RAM ]
GPU - [ NVIDIA GeForce GT 530 ]
Attachments:
Case inside Event 3.vi ‏19 KB
Case inside Event.ctl ‏6 KB
Case inside Event 2.ctl ‏6 KB

Okay. Accpeting that the design is not favorable and not advantageous when my program expands. I have begin to follow producer/consumer programming architecture.
Please find the attached program which is a simple producer consumer with event structure. I wonder how could I stop looping around the producer and consumer loops over and over again. I am pretty sure that this ENQUEUE ELEMENT loops back to the consumer loop and starts from begining.
I hope my first program in PC architecture with State machine and Event structure is correct. 
Abhilash S Nair
Research Assistant @ Photonic Devices and Systems lab
[ LabView professional Development System - Version 11.0 - 32-bit ]
LabView Gear:
1. NI PXI-7951R & NI 5761
2. The Imaging Source USB 3.0 monochrome camera with trigger : DMK 23UM021
OPERATING SYSTEM - [ MS windows 7 Home Premium 64-bit SP-1 ]
CPU - [Intel Core i7-2600 CPU @ 3.40Ghz ]
MEMORY - [ 16.0 GB RAM ]
GPU - [ NVIDIA GeForce GT 530 ]
Attachments:
Case inside Event 3.3-ProducerConsumer Event.vi ‏25 KB
Case inside Event.ctl ‏6 KB

Similar Messages

  • Run for loop inside event node

    Hi all, 
              We want to run for loop inside event node with 50ms delay. But when i am doing it the Labview is crashing. Please let me know if somebody did this.
    Thanks in advance,
    Regards,
    Harish. G
    Thanks & Regards,
    Harish. G.

    harishg92 wrote:
    Hi all, 
              We want to run for loop inside event node with 50ms delay. But when i am doing it the Labview is crashing. Please let me know if somebody did this.
    Thanks in advance,
    Regards,
    Harish. G
    You're implementing a For loop inside an event structure? (I don't know of any event "node" in which you can run a For loop)
    If so, that's a bad idea because LabVIEW won't be able to process any events while waiting for your For loop to get done, which might be why its crashing.
    There are tricks to accomplishing what you're trying to do without putting any for loops inside event structure. See what I have  attached and if it helps. "N" is number of times you run your For loop, timeout is whatever delay you want in each loop. This can be done in many ways without adding delays in events, another way could be to fire a separate subVI using Asynchronous call (without waiting for the VI to finish) during those delays, just make sure that such subVI finishes processing within your allocated time (that's how I'd ideally implement things). That method is better because you're doing minimal work inside events structure while using wait period wisely in a separate/parallel process.
    I hope that I understood you correctly and did not go off on a tangent.
    -BTC
    New Controls & Indicators made using vector graphics & animations? Click below for Pebbles UI
    Attachments:
    ForLoop inside Event Structure.vi ‏11 KB

  • How do I break a for loop (inside) and a while loop (outside) at the same time by a control button

    I have a while loop (outside) and a for loop (inside) and a control button within the for loop.  I want to stop the program by click the botton without finishing the for loop.  How can I do that?
    Thank you in advance.

    HI Please find attached snapshot Regards, Santosh
    Message Edited by SanRac on 12-17-2009 05:12 AM
    Message Edited by SanRac on 12-17-2009 05:13 AM
    Attachments:
    Snap1.png ‏4 KB

  • I have a for loop inside of while loop.when i press stop for while loop, i also would like to stop for loop.how can i solve this problem?thanks

    i have a for loop inside of while loop.when i press stop for while loop, i also would like to stop for loop.how can i solve this problem?thanks

    Hi fais,
    Following through with what JB suggested. The steps involved in replacing the inner for loop with a while loop are outlined below.
    You can replace the inner for loop with a while by doing the following.
    1) Right-click of the for loop and select "Repalce" then navigate to the "while loop".
    2) Make sure the tunnels you where indexing on with the for loop are still indexing.
    3) Drop an "array size" node on your diagram. Wire the array that determines the number of iterations your for loop executes into this "array size".
    4) Wire the output of the array size into the new while loop.
    5) Set the condition terminal to "stop if true".
    6)Drop an "OR" gate inside the while loop and wire its output to the while loops condition terminal.
    7) C
    reate a local of the boolean "stop" button, and wire it into one of the inputs of your OR gate. This will allow you to stop the inner loop.
    8) Drop a "less than" node inside the inner while loop.
    9) Wire your iteration count into the bottom input of the "less than".
    10) Wire the count (see step 4 above) into the top input of the less than. This will stop the inner loop when ever the inner loop has processed the last element of your array.
    Provided I have not mixed up my tops and bottoms this should accomplish the replacement.
    I will let others explain how to takle this task using the "case solution".
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • 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

  • For loop inside  a while loop, what order is that in big o??

    If say I have a for loop inside a while loop, then is that suppose to be in the order of O(n^2) right?? Is there any possibilities to change this into the order of O(n)??

    the other size and the temp size is abstact, which can be defined. This is actually for my union method, my teacher asks me to write this method using the order of O(n) which I think it is not possible. What do you guys think??
    Below is the code I have made:
    public Set<E> union(Set<E> other) {
              int count = 0;
              Iterator<E> iterator1 = other.iterator();
              while (iterator1.hasNext())
                   count++;
              Object[] temp = new Object [data.length+count];
              n = data.length+count;
              for (int i = 0; i<count; i++)
                   temp[i] = data;
              for (int j = count; j<temp.length; j++)
                   temp[j] = iterator1.next();
              data = temp;
              return null;
    but it still has same elements on it and I am thinking of a way on how to remove those same elements

  • How to pause and stop two "for loops" in an event

    Hi
    The main menu runs first and then goes to reading menu. After "Start Reading" button is pressed, the reading process will take readings.
    1) During reading process, if the "Pause Reading" button is pressed, I want that the two "for loops" are stopped and the two "for loop" counters do not reset. After the "Start Reading" button is pressed, the two "for loops" will continue to run.
    2) During reading process, if the "Stop Reading" button is pressed, I want that the two "for loops" are stopped and the two "for loop" counters are reset. After the "Start Reading" button is pressed, the two "for loops" will run again.
    The attached two VIs are simplified my real application. Any help will be appreciated.
    Thanks
    Steve
    Attachments:
    Main Menu Test.vi ‏9 KB
    Reading Menu Test.vi ‏23 KB

    You can't have those loops inside of the event structure.  Currently, when you press the start button, the reading has to finish before the event case finishes.  This will prevent the stop can cancel buttons from being processed by the event structure.
    You need another loop that can recieve commands from the event loop.  Look up the Queued Message Handler.  That should get you a good start on the command process.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Getting a for loop inside a while loop

    I've been having problems with the code below. I'm trying to get the 'while' loop to work so that the program will continue to run after a user types in a sentence. This is supposed to print out how many times a letter has been typed when a sentence has been put in, but it's not working right. It just keeps adding the first sentences numbers together even when a new sentence is typed out. I don't know what I'm doing wrong with this 'while' loop.
    import java.util.Scanner;
    import java.util.*;
    public class Count
    public static void main (String[] args)
    String phrase; // a string of characters
    int countBlank; // the number of blanks (spaces) in the phrase
    int length; // the length of the phrase
    int countA = 0; // the number of a's in the phrase
    int countT = 0; // the number of t's in the phrase
    int countE = 0;
    int countS = 0;
    char ch; // an individual character in the string
    Scanner scan = new Scanner(System.in);
    // Print a program header
    System.out.println ();
    System.out.println ("Character Counter");
    System.out.println ();
    // Read in a string and find its length
    System.out.println ("Enter a sentence or phrase ('quit' to quit): ");
    phrase = scan.nextLine();
    length = phrase.length();
    // Initialize counts
    countBlank = 0;
    // a while loop to allow user to keep entering phrases
       while (true)
       String line=scan.nextLine();
              System.out.println("Type quit to quit or enter a new phrase.");
         if(line.equals("quit"))
    break;
    // a for loop to go through the string character by character
    // and count the blank spaces
    for(int i = 0; i < phrase.length(); i++)
    ch = phrase.charAt(i);
    switch (ch)
    case ' ': countBlank++;
    break;
    case 'a':
    case 'A': countA++;
    break;
    case 't':
    case 'T': countT++;
    break;
    case 'e':
    case 'E': countE++;
    break;
    case 's':
    case 'S': countS++;
    break;
    // Print the results
    System.out.println ();
    System.out.println ("Number of blank spaces: " + countBlank);
    System.out.println ("Number of A's: " + countA);
    System.out.println ("Number of T's: " + countT);
    System.out.println ("Number of E's: " + countE);
    System.out.println ("Number of S's: " + countS);
    System.out.println ();
    }

    Ok well I don't really understand what you're saying, but here's an improved version of my code and I can get it to work, but I don't know how to turn the "do while" loop into just a "while" loop.
    import java.util.Scanner;
    public class Count3
         public static void main (String[] args) {
              String      phrase;           // a string of characters
              int      countBlank=0;      // the number of blanks (spaces) in the phrase
              int      length;           // the length of the phrase
              char      ch;                // an individual character in the string
              int      countA=0;       
              int      countE=0;
              int      countS=0;
              int      countT=0;
              String quit = new String("quit"); //String wasn't initialized
              Scanner scan = new Scanner(System.in);
              // Print a program header
              System.out.println ();
              System.out.println ("Character Counter");
              System.out.println ();
              do { //do-while loop
              // Read in a string and find its length
              System.out.println("Enter a sentence or phrase, or type \"quit\" to quit: ");
              phrase = scan.nextLine();
              length = phrase.length();
              // a for loop to go through the string character by character
              // and count the blank spaces, a's, e's, s', and t's
                   for (int i = 0; i <= length-1; i++) {
                        ch = phrase.charAt(i);
                        switch (ch) {
                             case ' ': countBlank++;
                             break;
                             case 'a':
                             case 'A': countA++;
                             break;
                             case 'e':
                             case 'E': countE++;
                             break;
                             case 's':
                             case 'S': countS++;
                             break;
                             case 't':
                             case 'T': countT++;
                             break;
                   // Print the results
                   System.out.println ();
                   System.out.println ("Number of blank spaces: " + countBlank);
                   System.out.println ("Number of a's: " + countA);
                   System.out.println ("Number of e's: " + countE);
                   System.out.println ("Number of s's: " + countS);
                   System.out.println ("Number of t's: " + countT);
                   System.out.println ();
                   countA=0; countE=0; countS=0; countT=0; countBlank=0;
              }while (!(phrase.equalsIgnoreCase(quit)));          
         }//end main
    }//end class Count

  • For loop pause till event occurs

    I'd like to know if it's possible pausing for loop in a fixed step till en event occurs.
    I need to use for loop index to indexing some vector's data, but the steps in for loop must be exectuted only if  precise condition occurs.
    thank you very much for possible solutions
    Francesco

    Without seeing any code, it is hard to recommend what to do.
    You probably want a State Machine architecture so that you can stay in a certain state of a while loop, then move on to the next step (state) when your condition is met.
    You could also use event structures.  You could also use notifiers or occurrences to hold the execution of your loop until the notifier is written to or occurrence executed in a parallel loop of your code.

  • Opening PDF in IE "breaking" for loop

    Hi,
    I have a dynamic PDF that is uploaded to a website.  When the PDF opens, the user has to fill in certain fields before clicking the "Next" button.  Upon clicking the Next button, I have a JavaScript function that sets certain fields access to required and then runs a for loop to check if any are empty.  The next event is setting those fields access back to optional. Lastly, a popup window refers the user to the empty fields (fields are shaded red, but not their borders).
    The problem occurs for one user who is using IE9 and has Reader X installed on his machine.  It only occurs when he opens it directly with his browser, if he downloads it to his desktop first he encounters no problem.  But using the browser makes filling in the fields on Page 1 glitchy, and then the loop doesn't work properly when he hits "Next".  The event setting the fields back to optional doesn't seem to be firing, and the popup never comes up.  So he's left with fields with red borders-which should not be happening.
    Any idea what could be causing this bug only when accessing via browser? I can't replicate the problem on any of my browsers, even after disabling Adobe add-ons in IE. 
    Thanks for any suggestions!

    Hi,
    I have a dynamic PDF that is uploaded to a website.  When the PDF opens, the user has to fill in certain fields before clicking the "Next" button.  Upon clicking the Next button, I have a JavaScript function that sets certain fields access to required and then runs a for loop to check if any are empty.  The next event is setting those fields access back to optional. Lastly, a popup window refers the user to the empty fields (fields are shaded red, but not their borders).
    The problem occurs for one user who is using IE9 and has Reader X installed on his machine.  It only occurs when he opens it directly with his browser, if he downloads it to his desktop first he encounters no problem.  But using the browser makes filling in the fields on Page 1 glitchy, and then the loop doesn't work properly when he hits "Next".  The event setting the fields back to optional doesn't seem to be firing, and the popup never comes up.  So he's left with fields with red borders-which should not be happening.
    Any idea what could be causing this bug only when accessing via browser? I can't replicate the problem on any of my browsers, even after disabling Adobe add-ons in IE. 
    Thanks for any suggestions!

  • Calculating Mileage & Breaking For Loop

    Hey all,
    I'm trying to create an application that calculates total mileage traveled and subtracts the initial mileage reading on the odometer. Can someone please tell me what I'm doing wrong? Also, can you tell me how I can break the For loop by inputting a negative number or typing in "stop"? I pasted the code below. Thanks for your help!
    import java.util.Scanner;
    public class Lab4{
         public static void main(String args[]){
              int miles[] = new int[10];
              double gallons[] = new double [10];
              double mpg[] = new double [10];
              Scanner kb = new Scanner(System.in);
              int count=0;
              double counter=0.0;
              for (int i = 0; i < 1; i++){
                   System.out.println("What is the reading on the odometer?");
                   miles[i] = kb.nextInt();
                   if (i > 0)
                        count = count + miles;
              for (int i = 1; i < 9; i++){
                   System.out.println("How many miles have you traveled since last filling up?");
                   miles[i] = kb.nextInt();
                   if (i > 0);
                        count = count + miles [i] - miles[0];
              System.out.print("You have traveled " + count);
              System.out.println(" miles");

    915786 wrote:
    I'm trying to create an application [...]
    public class Lab4{// which seams to be a School lesson...
    int miles[] = new int[10];
    //Do you know what this line does?
    miles[i] = kb.nextInt();
    //Any idea why this line does not compile?
    count = count + miles;
    // and this line either?
    I think you should go back two steps and learn the differences between objects, primitive types and arrays.
    bye
    TPD

  • While loop inside a event structure

    Dear
    I have no much concepts on event structure.
    Let's assume there is a dialog box with Okay and Cancel button.
    I put the event structure for Okay and Cancel button.
    In Okay event, there is a while loop for detecting some data continuously.
    In this case, I want to use Cancel button to stop the while loop during the detection.
    How can I do to receive signal from the Cancel button?
    Thank you in advance.

    I'm not sure that the event structure should be used to handle that situation : while the OK event is executing, either the Front panel is locked and new occuring event will be stored until the OK event is completed (so the Cancel button action will not be detected !) or the Front panel is unlocked (see below *) and the Cancel button action will stop the loop, but the Cancel button event case will not be executed, since the event has already been processed in the OK case !
    You should probably use a single button to run/stop the loop, as shown in the attachment
    * While editing the event case, unmark the "Lock front panel for this event complete" at the bottom. But of course, the code in the cancel case will not run, since the event occuredMessage Edité par chilly charly le 03-31-2007 05:27 PM
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Event button.vi ‏11 KB

  • For Loop Inside A For Loop

    Is it possible to execute all the iterations of the inside for loop for each iteration of the outside for loop? I have attached a screenshot of my program if it helps. If it is possible could you tell me how to do it plz?
    Solved!
    Go to Solution.
    Attachments:
    Capture.PNG ‏53 KB

    One thought I have is that I think you want those feedback nodes reinitializing for each iteration of the outter loop.  Personally, I would change them to be shift registers (it would clean up your diagram a little bit).
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Exit a while loop inside an event case

    Hi All, I have a multi-page program. One of it is used to read some analog signal via a USB block continuously.
    What I want is when clicking this page, this while loop is activated. Then we can monitor the data. When we click other pages or "Stop" button, this while loop will be terminated. And we can use the other pages to do something else.
    Right now I got difficuties in stop the while loop. I do not want to stop the running of the whole program, just want to jump out of this while loop then do other operation.
    Could anyone give me some advise how to do it? Thank you very much! 

    Hi RavensFan, thank you for your reply.Actually this is not my real code  because the original one is very very compliacted.
    In real code, the tab control you see in inside the bigger while loop, that loop makes the whole program work.
    And as what I pointed, the purpose is when I click this tab (if we do not want it to trigger, we can place another "START" button to trigger), an internal while loop inside begins to run. This while loop keeps showing the real time analog signal.
    And if I do not want to use this "real time monitoring" function, I want to click somewhere (or doing anything else that can work) to jump out of this internal while loop and keep on using some other functions of the program.
    Could you advise about that? Thank you very much! 

  • While loop with stop button within event structure locks up front panel.

    I am not sure if this is a bug with my program or a bug within LabVIEW.  If you believe that this is a bug with my program then I will post my program to be looked at.
    The problem I am having is there is a while loop within an event structure that fires when a particular value changes.  Once the "Activate" button is pressed the while loop within the event structure starts going with a polling frequency of 1hz (1000ms wired to the "wait till next ms multiple" vi).  There is a "Deactivate" button that is wired to the stop control of the while loop and an outter while loop that resets the event structure so that the activate button is being listened to again.
    Once inside the while loop, however, none of the button are responsive within the front panel.  The VI continues to run, and only 60% of my CPU is being consumed, but none of the button or scroll bars work.  The only way for me to terminate the program is with the "Abort" button next to the "Run" button.  If I remove the event structure so that the while loop in question runs as soon as the program starts, the front panel remains responsive.  I've inserted probes within the while loop and verified that it is not running prior to the "Activate" button being asserted, and it is running after the assertion of the "Activate" button with the expected polling frequency set by the "wait till next ms multiple" vi.
    Can anyone help?  Do I need to post my code?
    -Nic

    It is typically not a good idea to stall an event structure by placing loops inside event cases. What good is an event structure if it is not free to repond to events?
    Have a look at some alternative solutions, such as in the following link:
    http://forums.ni.com/ni/board/message?board.id=170&message.id=224817#M224817
    LabVIEW Champion . Do more with less code and in less time .

Maybe you are looking for