While loop doesnt start

Hi, its me again.
Still working on the same program. The program just reads some values and puts them into an array.
This is timed, but not exaclty correct. It waits for 10ms and then counts 10 up one the time-variable.
When u have a measurement time of 3 hz, it waits until the remainder of time is 0.
I calculate this like so:
remainder = time / (1000 / rate)
So if rate = 3, the time has to be 333,3333333 to enter the while loop.
Thinking of this, the programs while loop has to run every ms, which is kinda impossible IMHO.
So how to solve this?
And then another problem, the while loop which has the calculate loop
etc inside of it, doesnt run on program execution. I'm wondering why
not...
Attachments:
organLog.vi ‏149 KB

You have to familiarize with the basic concepts of dataflow. Look at some example programs. Do some online tutorials.
In this particular case:
All loops on the left cannot start until the loop on the right finishes. They must wait for the boolean wires to contain data and this only happens once the loop in the right exits.
LabVIEW Champion . Do more with less code and in less time .

Similar Messages

  • Stop dependant while loops with 1 button

    Hi,
    I am developing a utility that allows a user to configure up to 2 devices (both use same driver with a different board number), click initialize, which then brings up a file dialog and displays arrays for the data to be collected and some error messages for each measurement.  The user then clicks the Start/Stop button to begin collecting and logging data.  Currently i have a Wait(ms) block to allow the user to set often the measurement should be made.  Currently the Start/Stop button allows collection to be started, paused, and started again.  My problem is trying to have a master stop button that should stop all loops immediately when it is pressed.
    I tried using a global variable for the stop button, but the measurement and logging while loop doesnt stop until after the wait(ms) block times out.  Can anyone give suggestions.  If i need to restructure the VI into different loops, I can do that.  I just want to understand the right way to program something like this.
    The VIs are attached.  I removed the device specific measurement VI so that anyone can open the vis and run them to see how it works.
    Attachments:
    2Devices_withoutMeasurementVI.vi ‏112 KB
    BuildOutput.vi ‏27 KB
    stopGlobal.vi ‏5 KB

    Ok.  I had a chance to take a look at your code and I think you don't quite understand the concept of "dataflow".  Let me see if I can help.
    First of all...when I refer to your upper structure, I am referring to the first while loop, sequence structure, and subsequent while loops.  When I refer to your lower structure, I am referring to the while loop containing the event structure.  Just so we get our terminology straight.
    I believe that you are under the illusion that your upper structure contains three parallel while loops.  It does not.  It contains three SERIAL while loops.  There is dataflow dependency between the while loops.  The sequence structure requires data that is not available until the first while loop has finished executing, so the sequence structure cannot start executing until the first while loop has terminated.
    The second while loop requires inputs from the first frame of the sequence structure (which, by the way, you don't need and should get rid of...the sequence structure, I mean), so it cannot start executing until the first frame of the sequence structure has terminated.  The third while loop requires inputs from the second while loop...so, again, the third while loop cannot run until the second while loop has finished executing.
    Now, for your stop button.  You have that global stopping all three loops.  So here's what is happening in your program:
    Your program starts.  The first while loop executes in parallel with the loop which contains the event structure.
    At some point you press the "stop" button.  Both the first while loop and the loop containing the event structure finish executing.
    The first frame of your sequence structure executes.
    The second frame of your sequence structure executes.  The second while loop reads the "stop" value from the global, so it executes once and then finishes.
    The third while loop starts executing.  Again, the loop reads the "stop" value from the global, so it executes once and then finishes.
    Then your program terminates.
    You need to restructure your program, because right now it doesn't make any sense at all.  Your block diagram would benefit from some serious tidying up as well, your wiring is a mess.  I suggest you look into a state machine architecture for this program.

  • Try catch problem in a while loop

    I have computerGuess set to -1 and that starts the while loop.
    but I need to catch exceptions that the user doesnt enter a string or anything other than a number between 1 and 1000.
    but computerGuess is an int so that the while loop will start and I wanted to reset computerGuess from the user input using nextInt().
    The problem is if I want to catch exceptions I have to take a string and parse it.
    import java.util.Scanner;
    public class Game {
         //initiate variables
         String computerStart = "yes";
         String correct = "correct";
         String playerStart = "no";
         int computerGuess = 500;
    public void Start()
         //setup scanner
         Scanner input = new Scanner(System.in);
         int number = (int)(Math.random()*1001);
         System.out.println(welcome());
         String firstAnswer = input.nextLine();
         if(firstAnswer.equalsIgnoreCase(computerStart)== true)
              System.out.println(computerGuess());
              //while (userAnswer.equalsIgnoreCase(correct) == false){
                   System.out.println();
         if(firstAnswer.equalsIgnoreCase(playerStart) == true)
              long startTime = System.currentTimeMillis();
              int currentGuess = -1;
              while (currentGuess != number){
              System.out.println(playerGuess());
              String guess = input.next();
              //currentGuess = Integer.parseInt(guess);
              if (currentGuess < number)
                   System.out.println("too low");
              if (currentGuess > number)
                   System.out.println("too high");
              if (currentGuess == number)
                   long endTime = System.currentTimeMillis();
                   System.out.println("Well done, the number is " + number);
              int i = -1;
              try {
                i = Integer.parseInt(guess);
                   } catch (NumberFormatException nfe) {
                        //System.out.println("Incorrect input, please try again.");
              if ( i < 0 || i > 1000 ) {
                   System.out.println("Incorrect input, please try again.");
         private String computerGuess()
               String comGuess = ("The computer will guess your number.\n" +
                        "Please enter \"too high\", \"too low\" or \"correct\" accordingly.");
               return comGuess;
         private String welcome()
              String gameWelcome = "Welcome to the guessing game \n" +
                                        "The objective is to guess a number between 1 and 1000.\n" +
                                        "You can guess the computer's number or it can guess your's.\n" +
                                        "You may enter \"quit\" at any time to exit.\n" +
                                        "Would you like the computer to do the guessing?";
              return gameWelcome;
         private String playerGuess()
              String playerWillGuess = "Guess a number between 1 and 1000.";
              return playerWillGuess;
    }The catch works , but because computerGuess is int -1 so that the while loop will run, I cannot use the input to change computerGuess because it is a string.

    the i was a mistake. and i commented on the other code, because it wasnt working at that moment. I need help understanding the try catch method.
    I want to catch any input that isn't an integer , and I would also like to catch any input that isn't a string at other parts of my program.

  • Stop While and again START

    Hi!
    Its very nice. Plz give me the solution for the following problem --
    Plz find the attached vi ( 1. main 2. Mouse over is sub vi of "main")
    I want to make controls on my front panel mouse sensitive. I have one vi (Mouse over) which full fill my requirement. But when i call it as sub vi i will get mouse sensitivity only once. i.e when i call sub vi for the first time i will have no problem,  but when i came back to main vi and again enter to sub vi i lost control. vi gets hanged.
    When i analyse this, i concluded that its problem of while loop switching. When i stop sub vi, while loop gets stoped, but when i call back again subvi, that while loop doesnt restart  again.
    SO tell me how to restart while loop in program once it is stopped. Give me the solution.
    Thanks
    Kaustubh
    VC (Pune)
    INDIA
    Attachments:
    main.zip ‏20 KB

    Hi Kaustubh_vc,
    i´ve modified your attached SubVI . You have
    to unregister your user events in SubVI so if you call your vi secondly
    your user event is new registered and afterward unregistered.
    Hope it helps
    Attachments:
    main_changed.zip ‏15 KB

  • While loop in a Hash Map

    My while loop doesnt seem to work in a hash map, it works fine when I loop an array list.
    It compiles but it doesnt seem to find any employees, should I use another loop?
    {code
    public Employee find(String id)
    Employee foundEmployee = null;
    int index = 0;
    boolean found = false;
    while(index < register.size() && !found){
    Employee right = register.get(index);
    String namn = right.getName();
    if (namn.equals(id)){
    foundEmployee = right;
    found = true;
    index++;
    return foundEmployee;

A: while loop in a Hash Map

what if you looped on the key set?
  public Employee find(String id)
    Employee foundEmployee = null;
    Set<Integer> keySet = register.keySet();
    for (Integer key : keySet)
      Employee right = register.get(key);
      if (right.getName().equals(id))
        foundEmployee = right;
        break;
    return foundEmployee;
  }

what if you looped on the key set?
  public Employee find(String id)
    Employee foundEmployee = null;
    Set<Integer> keySet = register.keySet();
    for (Integer key : keySet)
      Employee right = register.get(key);
      if (right.getName().equals(id))
        foundEmployee = right;
        break;
    return foundEmployee;
  }

  • How do I create a start/stop button for each separate while loop within my program, when each of them does a different task?

    I have a multimeter VI with separate while loops to accomplish the different tasks of reading  voltage, current, etc. Each while loop has a stop button, but I need a button that will have to be pressed in order for the while loop to even start. I tried putting another while loop around the present one, but it still has to run once before it will stop. I want the user to have to press the button before it runs, because they interfere with each other.
    I am just learning so patience and your kind assistance is greatly appreciated!
    ElectroKate

    iZACHdx wrote:
    Hello,
    I'm not entirely clear with everything you have going on and what you want your final functionality to be, but you can use sequence structures to prevent a loop from starting until the user presses a button like this:
    -Zach
    I have to ask, why is an NI employee using examples using sequence frames? The same thing could be accomplished using data flow by simply wiring the value of the first stop button out of teh first while loop and connecting it to the second loop. This would then use data flow to control the sequence. Why show new users bad programming methods?
    As to the original question I would concur with altenbach on using an event structure.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Problem with while loop in thread: starting an audiostream

    Hello guys,
    I'm doing this project for school and I'm trying to make a simple app that plays a number of samples and forms a beat, baed on which buttons on the screen are pressed, think like fruity loops. But perhaps a screenshot of my unfnished GUI makes things a bit more clear:
    [http://www.speedyshare.com/794260193.html]
    Anyway, on pressing the play button, I start building an arraylist with all the selected samples and start playing them. Once the end of the "screen" is reached it should start playing again, this is the while loop:
    public void run(){
            //System.out.println("Wavfiles.size =" + getWavfiles().size());
            System.out.println(repeatperiod);
            if (getWavfiles() == null) {
                System.out.println("Error: list of Wavfiles is empty, cannot start playing.");
            else{
                if(!active) return;
                while(active){
                    System.out.println("Wavfiles.size =" + getWavfiles().size());
                    for (int i=0; i<getWavfiles().size(); i++){
                        Wavplayer filePlayer = new Wavplayer(getWavfiles().get(i).getStream());
                        Timer timer = new Timer();
                        //timer.scheduleAtFixedRate(filePlayer, getWavfiles().get(i).getStartTime(),repeatperiod);
                        timer.schedule(filePlayer, getWavfiles().get(i).getStartTime());
                    try {
                        Thread.sleep(repeatperiod);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(LineBuilder.class.getName()).log(Level.SEVERE, null, ex);
        }But once the second iteration should begin, I'm getting nullpointerexceptions. These nullpointerexceptions come exactly when the second period starts so I suppose the sleep works :-) The nullpointerexception comes from the wavfile I try to play. Wavfile class:
    package BeatMixer.audio;
    import java.io.ByteArrayInputStream;
    import java.io.IOException;
    import java.util.TimerTask;
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.LineUnavailableException;
    import javax.sound.sampled.SourceDataLine;
    import javax.sound.sampled.UnsupportedAudioFileException;
    public class Wavplayer extends TimerTask {
            private SourceDataLine auline;
            private AudioInputStream audioInputStream;
         private final int EXTERNAL_BUFFER_SIZE = 524288; // 128Kb
         public Wavplayer(ByteArrayInputStream wavstream) {
              try {
                   audioInputStream = AudioSystem.getAudioInputStream(wavstream);
              } catch (UnsupportedAudioFileException e1) {
                   e1.printStackTrace();
                   return;
              } catch (IOException e1) {
                   e1.printStackTrace();
                   return;
                    AudioFormat format = audioInputStream.getFormat();
              DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
                    try {
                   auline = (SourceDataLine) AudioSystem.getLine(info);
                   auline.open(format);
              } catch (LineUnavailableException e) {
                   e.printStackTrace();
                   return;
              } catch (Exception e) {
                   e.printStackTrace();
                   return;
        @Override
         public void run() {
                    System.out.println(auline);
              auline.start();
              int nBytesRead = 0;
              byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];
              try {
                   while (nBytesRead != -1) {
                        nBytesRead = audioInputStream.read(abData, 0, abData.length);
                        if (nBytesRead >= 0)
                             auline.write(abData, 0, nBytesRead);
              } catch (IOException e) {
                   e.printStackTrace();
                   return;
              } finally {
                   auline.drain();
                   auline.close();
    }auline is null on second iteration, in fact, getAudioInputStream doesn't really work anymore, and I don't know why because I don't change anything about my list of wavfiles as far as I know... Any thoughts or extra info needed?
    Edited by: Lorre on May 26, 2008 12:22 PM

    Is my question not clear enough? Do you need more info? Or is nobody here familiar with javax.sound.sampled?
    Edited by: Lorre on May 26, 2008 2:07 PM

  • Start, stop and restart while loops

    Hi, my qustion is i have 2 example a and example b. Example b lets u start counting up in seconds when u want to. as long as the toggle switchs are in correct position. it also lets u start, stop and restart if need be. i want to be able to that with example a, but for some reason the while loop always sets of running independent of what position the the toggle switch. Any help greatly appreciated.
    Thanks Stuart
    Attachments:
    examplealib.llb ‏202 KB
    exampleb.vi ‏25 KB

    An example as the attachment.
    Attachments:
    switch.vi ‏23 KB

  • Stop and start while loop on order

    Hallo everyone,
    I have this small IV, it means nothing but I want to know if it's possible to control each while loop. what I wish to do is to press the boolean button, then the while loop starts running and when i press it again the loop stops but when I press it again it works again, not that the program stops running at all. not only that but I need it for both loops. so i run one and stop the other then stop one and run the other and so on...
    I dont know if this is possible and its not necessary to be done with loops, I just wrote loops because this is what I can do and understand, if there are any other possibilities then please feel free to share it with me.
    Attachments:
    Unbenannt 3.vi ‏178 KB

    pcardinale wrote:
    Perhaps something like this.
    I don't think we need to involve such a huge amount of code and new concepts (timed loop, notifiers, subVIs, clusters, arrays, event structures, etc.),  to solve such a simple problem. (This might turn off a beginner!).
    Here's what I would do.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    TwoCharts.png ‏14 KB
    Unbenannt 3Mod.vi ‏17 KB

  • How to start/stop 2 parallel while loops

    My question might be simple to answer for experts, but as a Labview beginner would be great to receive your help:
    I hav a VI with two parallel while loops. The first loop runs in a tact of 100 ms to aquire voltage, speed and to output a speed setpoint for a motor in the same tact, read from a table.
    Finally all values are written to a log-file.
    The question: As soon as I run my VI, data logging starts too and my motor runs. How can I implement a button to start all loops parallel, and how can they be parallel be stopped too if I want to stop measurement? Tryed to set a local variable for both stop buttons but it didn´t work.
    Thanx to all, Markus
    Attachments:
    screenshot.JPG ‏74 KB
    Measure and log data.vi ‏147 KB

    SnowMule wrote:
    Starting the two is easy; use the error cluster to enforce dataflow.
    Stopping them is a little trickier; the code you have now isn't very expandable so I'd recommend finding a different architecture.  A notifier functions like a queue with a size of 1, a queue works well for sending commands/data between loops.
    There is one other significant difference between queues and notifiers. A queue can only have one reader. If you have multiple readers of a queue who reads it will be random. A notifier can have multiple listeners. It fact, that is it's purpose.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Start stop while loop with tab control

    I want to be able to start and stop a while loop by entering and leaving a tab.  I am using an event structure to do so but it doesn't seem elegant or the right way to do this.  The only way I was able to get it to kind of work is by unchecking the lock front panel box in the event structure.  I have attached a sample vi of what I have so far.
    Solved!
    Go to Solution.
    Attachments:
    Loop test.vi ‏16 KB

    The problem is that you can't even stop the program by hitting the stop button until you leave the tab, which is not a friendly user interface.
    Event structures should just handle basic user events.  Any given event case should not take a long time to run.  While you are in the diagnostics tab, your code is stuck in that while loop.  Although fixing the lock front panel allows you to do other things, the LabVIEW is just queuing up all of those other UI events (like Stop button value change) and can't handle them until the inner while loop stops and allows the outer while loop to iterate again.
    You should have a parallel while loop to handle the waveform graph.  You can use notifiers or queues or an action engine FGV (see Ben's Action Engine Nugget) to pass the starting or stopping of the waveform graph update to the parallel while loop.

  • Re-start producer while loop

    Hi,
    I'm trying to figure out the best way to implement a producer/consumer architecture. I'm hoping there is something simple that I don't understand.
    I have a state machine executing in it's while loop, doing things like saving and processing data. The data is being passed through a queue from a separate while loop. I'm currently starting that producer loop using occurrences, and I can stop it with a local variable. 
    What I can't figure out is how to restart that loop from within the state machine?  In essence, I'd like to have a switch that says "Collect Data" and it will turn the producer while loop on and off but leave the main program running in the meantime. 
    Thanks for any suggestions. 
    mike

    Basically, i find producer/consumer architectures where the consumer creates "commands" (Edit: which do more than simple notification tasks) for the producer quite absurd.
    I would switch to a three loop architecture:
    Producer A is responsible for UI display/control. It feeds Consumer A which is infact Producer B.
    Producer B (aka Consumer A) is the DAQ consumer. It will acquire data due to the settings passed by Producer A. The DAQ data will be passed to Consumer B.
    Consumer B handles the data passed by Producer B. If necessary, it can create custom user events in order to notify Producer A about certain situations in the software.
    An approach with an Action Engine can be similar in regard to functionality, has its own advantages and disadantages.
    hope this helps,
    Norbert
    Message Edited by Norbert B on 01-14-2010 12:13 PM
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Delay to start a "while loop"

    Yes I would like to run a while loop only after I switch on a start button. For some reason the loop does not start. I put the while loop in a Case structure which I want to make true with the start switch.

    Hi,
    ALT 1: If the button is false, the case does nothing, and the program is
    finished. So, you'll have to put the entire program in another while loop
    (that quits whenthe program is done), or use the run continuously button to
    start the program.
    ALT 2: Make a while loop before the while loop that you have. Wire the
    button to the stop criterium, and change the stop criterium to "stop when
    true". Wire anything (e.g. the button wire) to the second while loop, just
    to synchronise the execution.
    Put a "wait ms", with e.g. 50 ms, in the while loops, or your program will
    use up 100% processor time. This is not nesseccary if the while loop only
    runs for a short (<200 ms) period.
    Regards,
    Wiebe.
    "JShaw" wrote in message
    news:5065000000080000003C80000
    [email protected]..
    > Yes I would like to run a while loop only after I switch on a start
    > button. For some reason the loop does not start. I put the while loop
    > in a Case structure which I want to make true with the start switch.

  • Starting stopping multiple while loops

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

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

  • Starting new while loop while old one still running

    Hi!
    I am attempting to write video images to AVI files. I want to give the user the option to decide when they want to begin to capture the images. I place the "start recording" button in one loop and the image acquisition and AVI Write subVIs in another loop. LabVIEW won't allow me to continue on with the image acquisition loop until I finish with the "start recording" loop. Any ideas how to fix this (to allow the image acquisition to start and continue having LabVIEW check for a button press on "start recording")?
    Attachments:
    Capture_and_Save_as_AVI.vi ‏177 KB

    Thanks. I suspected as much. In any event, I can't seem to find a good configuration of while loops and case structures which will produce the desired results. I want to start acquiring images and allow the user to choose to start recording at any time he desires. This issue is further complicated by the fact that the status of the "Start recording" must be checked at all times, but only initialized once, while the AVI Write Frame depends on that first initialization step but must be looped continuously aferwards in order to 'keep up' with the images being acquired. In the newly attached example, I placed the case structure inside the image acquisition while loop and the avi write frame inside a while loop inside of that case structure. unfortunately,
    labview decides to stay inside the avi write frame while loop after entering, instead of returning to the image acquisition while loop. i can't place the avi write frame inside the general image acquisition while loop because then labview will think i want to initialize the avi write frame right away and will return an error when avi write frame isn't provided with an avi refnum. Ideas?
    Attachments:
    Capture_and_Save_as_AVI.vi ‏174 KB

  • Maybe you are looking for

    • Can't get video to work

      I followed tutorials at Adobe, Lynda.com and Stackoverflow but can't get my video to work in my Edge Animate presentation. Here is the code I used. "holder" refers to a rectangle on stage. I put the code into a timeline trigger as per the tutorial. v

    • How to create a link

      i have to create a link in servlets ,this link should pop up a file where in client can modify this file & should be able to save it , i should also be able to receive this modified file. I have absolutely no idea of how to start can anyone on the li

    • Problem: launch javaBean method in Javascript?

      I want to launch a method of javaBean in javascript, but it always occur errors. the main code is as following: <jsp:useBean id="getPropertyBean" class="mmes.BeanSetExamProperty" scope="page"/> <html><head> <script language="JavaScript" type="text/Ja

    • Create a view with a changing where clause

      Hi all, i'm developing an application with oracle forms i want to create a view in the database with a different where clause in every time , the where clause is determined due to the department id of the current user . thanks alot.

    • Translation of Columns and Table Names

      Hi, We are starting a large migration project and we have a mix of dutch and english developers. I was wondering if there is any clever ways to translate column names and table names. Not physically translate the text but store the english column nam