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

Similar Messages

  • 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

  • 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

  • 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

  • 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

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

  • 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

  • Trouble running for loop

         public void enterBackMultiple(int number)
              System.out.println("Number of times to run loop is: " + number);
              for(int i = 0; i < number; i++);
                   line.enqueue(new Customer());
                   System.out.println("Adding a customer.");
              System.out.println("Done running enterBackMultiple Method.");
         }When I pass in 5, the loop is suppose to run 5 times. Instead I get this:
    Number of times to run loop is: 5
    Adding a customer.
    Done running enterBackMultiple Method.
    Which shows that the for loop only ran once. It should've printed "Adding a customer" 5 times. Whats going on??
    EDIT: nvm i see whats wrong. stupid mistake. Thanks.
    Edited by: backtoreality15 on May 19, 2008 5:40 PM

    Here is your for loop again. See if you can spot the mistake now.
    for(int i = 0; i < number; i++); {
        line.enqueue(new Customer());
        System.out.println("Adding a customer.");
    }Edited by: flounder on May 20, 2008 10:54 AM
    Ah, so you already spotted the mistake.

  • Variable not defined after running for() loop.

    Hi,
    I have a little problem, I have created a for loop, which seems to work, except that a variable within the for() loop gets lost, because if I try to call the variable after the loop, it says it's not there. anyway, here is my code, followed by the error. Thanks!
    <%
    Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:testdb");
    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    String sql_count = "SELECT COUNT(*) FROM users";
    ResultSet cn = stmt.executeQuery(sql_count);
    cn.first();
    int row_count = cn.getInt(1);
    int num = (int)(Math.random() * (row_count));
    int inum;
    for (inum=0; inum<row_count; inum++)
    int jnum = inum + num;
    if (jnum >= row_count) { jnum = 1; }
    String sql = "SELECT * FROM users WHERE ID = "+jnum+"";
    ResultSet rs = stmt.executeQuery(sql);
    int ce = rs.getInt("cr_earned");
    int cu = rs.getInt("cr_used");
    if ((ce-cu) > 0) { inum = row_count + 1; }
    String sql = "SELECT * FROM users WHERE ID = "+jnum+"";
    ResultSet rs = stmt.executeQuery(sql);
    rs.first();
    String url = rs.getString("url");
    con.close();
    %>
    ***********************ERROR***********************
    Generated servlet error:
    C:\tomcat\jakarta-tomcat-4.0\work\localhost\examples\gtt\surf$jsp.java:93: Undefined variable or class name: rs
    rs.first();
    ^
    An error occurred between lines: 17 and 43 in the jsp file: /gtt/surf.jsp
    Generated servlet error:
    C:\tomcat\jakarta-tomcat-4.0\work\localhost\examples\gtt\surf$jsp.java:94: Undefined variable or class name: rs
    String url = rs.getString("url");
    ^

    now i've defined them all before the loop and I get this error. Error is following modified code below.
    <%
    Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:testdb");
    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    String sql_count = "SELECT COUNT(*) FROM users";
    ResultSet cn = stmt.executeQuery(sql_count);
    cn.first();
    int row_count = cn.getInt(1);
    int num = (int)(Math.random() * (row_count));
    int inum;
    int jnum;
    ResultSet rs;
    for (inum=0; inum<row_count; inum++)
    jnum = inum + num;
    if (jnum >= row_count) { jnum = 1; }
    String sql = "SELECT * FROM users WHERE ID = "+jnum+"";
    rs = stmt.executeQuery(sql);
    int ce = rs.getInt("cr_earned");
    int cu = rs.getInt("cr_used");
    if ((ce-cu) > 0) { inum = row_count + 1; }
    rs.first();
    String url = rs.getString("url");
    con.close();
    %>
    ***********ERROR***************
    An error occurred between lines: 17 and 45 in the jsp file: /gtt/surf.jsp
    Generated servlet error:
    C:\tomcat\jakarta-tomcat-4.0\work\localhost\examples\gtt\surf$jsp.java:95: Variable rs may not have been initialized.
    rs.first();
    ^
    Thanks anyone.... ;-)

  • Include FOR LOOP inside a parameter

    Hi Programmers,
    I have this portion of code where I want it to display list of all customers inside the email being sent to a sales manager. However, no result generated.
    message:='Sir/Madam,'||CHR(10)||CHR(10)||'Display List of Customers '||CHR(10)||CHR(10)||
    lpad('List of Customers ', 50)||CHR(10)||CHR(10)||
    FOR customer_rec in customer_cur
    LOOP
    lpad('Customer Name : ', 50)||customer_rec.first_name||' '||customer_rec.last_name||CHR(10)||
    lpad('Customer Office Address : ', 50)||customer_rec.address||CHR(10)||
    lpad('Postcode : ', 50)||customer_rec.postcode||CHR(10)||
    lpad('State : ', 50)||customer_rec.state||||CHR(10)||CHR(10)||
    END LOOP;
    'End of list';
    Please help..

    I don't understand why you created 3 duplicated thread? And on top of that you didn't even bother to format the code?
    It's lack of respect i would say .....

  • For loop in formula node

    Hi,
    I wanna do some signal processing after I got the magnitude and phase infos from FFT. But the errors say that there is undefined variables.  I am just wondering that here absP and angleP are both vectors. Can I express them like what I did in the attached vi? 3x.
    Huihui
    Attachments:
    Untitled 12.vi ‏9 KB

    Hi huihui,
    do you just want to know the real and imaginary values of your signal?
    Why use formula node at all?
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    Untitled 12.vi ‏13 KB

  • Is there a way to run a For Loop independen​tly within a While Loop in LabVIEW 2013?

    In my program I would like to run a For loop inside of a While loop, and have them run independently, at their own execution rates.  As a test, I wrote a simple VI with a While loop with 1 second timing, and into this I inserted a For loop with 3 second timing.  I created indicators for both iteration terminals.  Upon running the VI, I found the While loop waits for the For loop to run N times before the While loop executes again.  I also found that sometimes the first iteration of the For loop will end at 1 second rather than 3 seconds, and the STOP button to terminate execution of the While loop does not always work.
    Solved!
    Go to Solution.

    ksinks wrote:
    Thanks, how would you synchronize the loops?  I have gone through the Getting Started exercises and manual.
    Why would synchronization matter? Did you want them to run independantly at their own speed or not?
    Regardless, there's a synchronization pallette with functions for this, as Occurance.
    Other solutions include a common loop counter and a case structure executing every X'th iteration, or having the faster loop send a queue or event every X'th loop that controls the slower loop.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • Delayed Movement For Loop

    I know this question has probably been asked and answered before, but after searching/reading in the forums, I'm still confused.
    So I would like my VI to effectively move a stage a given distance with incremental sizes with pauses of between each step.
    Effectively: "Go To" _____ With X step size: causes the VI to: move, pause, move pause...etc until the stage has reached the end.
    To accomplish this I set up a for loop inside a case structure, and took the "Go To" / by Step Size to get the number of iterations the loop aught to run (labview apparently rounds the double result to the integer form), and then I send the "Step Size" to the MoveAbs VI.
    I am not sure if my logic is terribly off, but when I perform the command, the stage at least moves, but not to the correct location.When I inserted probes, they list the correct values being sent to the subvi's etc...
    Does anyone have an idea why this would not work? Any better ideas to institute this type of motion?
    Thanks
    Attachments:
    delayedmotiontrial2.vi ‏85 KB

    Hey Tim,
    I've got another question for you--I've been working on the program and I think I finally understand the basic outline. I've been trying to add other subvi's to increase functionality and I came across a problem:
    The error list says that the selector values of the case structure are not unique--which is true of the program I am sending you. So naturally I deleted the extra "VI INI" which was tagged onto the default case. However doing so caused my program to crash--or more accurately cycle in an infinite loop. The program initializes over and over again. The "INI VI" sends another "INI VI" to the array and gets stuck.
    I am not quite sure what is wrong, because when I looked at the original program you had sent to me, and earlier versions I had edited, I noticed that they have the same code within the "INI VI" case...in addition, now when I open previous programs--that were functioning perfectly well before--I get the same error message complaining about "not unique selector values". I honestly don't recall ever adding "INI VI" to the default case...
    I am attaching the program and was wondering your thoughts, especially given the retrospective error...
    Let me know if I was unclear in explaining the problem etc...and thanks again for your help. Others' input welcomed too!
    Nathan
    Attachments:
    DelayedMotionTrial7c.vi ‏85 KB
    State Machine States.ctl ‏5 KB

  • Creating an array in a 'for' loop (resetting loop count)

    Hi,
    I am trying to integrate an acceleration signal coming from a CRIO analogue input to obtain the speed and then further integrate to get the displacement of a vibration system.
    I understand that in order to perform the integration, an array has to be fed in. My problem is that I could not buffer the signal in a buffer block as I couldn't find any buffer blocks. so I decided to create my an array of data using a 'for' loop. The 'for' loop nests inside a timed loop. The problem that I got stuck at is how to reset the 'for' loop in order to refill the buffer again at every iteration of the outer timed loop.
    I have attached the code if that helps. Note that I am using labview 2013.
    I would be gratefull if someone who had encountered a similar issue before can help me.
    Regards
    Ali
    Solved!
    Go to Solution.
    Attachments:
    acc_test.vi ‏42 KB

    Dear Altenbach,
    Many thanks for your reply.
    I need to make it clear that I have not had enough hands-on with labview, I have only used it for sometime in the past and now I have to in order to perform some active damping on a 50Hz running machine. I must stress the fact that what i find more intuitive to do in a different programming language (matlab or C) is not as straightforward in labview. so please bear with me if my code has basic mistakes .
    All what i am trying to do is obtain the speed and position from an acclerometer signal. unfortunately i dont have a position sensor so i have to measure acceleration then perform time integrations in order to obtain the speed and position respectively. I am using a compact Rio (later in FPGA mode) to take physical measurements of acceleration from the vibratory machine and where i managed to do this bit successfully. when it came to performing the integration, i had to create an array inside my timed loop since i couldn't find a buffer block. I implemented a 'for' loop inside a timed loop in order to build the array. however i got stuck at resetting the count of the 'for' loop in order to refill the array with new values at every new iteration of the outer timed loop. unfortunately, even a sensible answer has been suggested before, i dont seem to have been capable of doing it yet. I really spent all my day trying to figure a way out but not achieved it yet, nevertheless I have learnt many many things by playing around.
    I would be gratefull if you could comment on a possible way of doing what i am trying to do.
    Kind Regards
    Ali

Maybe you are looking for

  • How can I return my downloaded apps back into my iphone

    I was not getting anything to come up on my iPhone, I would press an app and it would go into the loading mode, but nothing else would happen.  I then restored my phone and it took me back to the basics.  I was just wondering if it would be possible

  • Minimize JMenuBar application to systemtray

    Hi, I have an application which is entirely a JMenu/JMenuBar setup. I do initially extend JFrame, but never actually "create" a JFrame. Now I've searched quite a bit for help to minimize to the systemtray and found help, however it's always relating

  • Text selection tool is too bad since many years ago

    selected easily in skim on MAC selected dont know what in acrobatX on MAC  -  -b

  • Is padding required while posting to SAP

    Hi Is padding really required for a number(ex: if a field has max length is 10, can it have only 3 out of it and left others)  or string(ex: if a field has max length is 10 char, can it have only 4 out of it and left others)while posting as an IDoc t

  • Where does Delta Mechanism acts in LO?

    Hi, Where does Delta Mechansim(V3 Update) acts in LO-Extraction?