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.

Similar Messages

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

  • 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

  • Iterate while loop on command

    This seems like it should be a relatively simple application of a while loop, but I can't seem to find the solution :/ Basically I have a string control on my front panel for a filename (minus path/extension), and when I start up the VI I check if the file already exists. If it does, I'd like to start a while-loop in which each subsequent iteration only occurs when the string control is changed by the user.
    The way I have it wired up now works fine (see attached), but it loops every 50 ms even while there's an invalid string. If possible I'd like to pass to the next iteration only after the control value has changed. This way I can display an error dialog of some sort that won't pop up every 50 ms. (Note: this is a piece of code from a subVI, hence the refnums and property nodes.)
    Thank you!
    Attachments:
    input_loop.vi ‏12 KB

    phogan wrote:
    The reason for all the refnums is that I'm trying to check controls that are on the main front panel while I'm within this subVI loop. If you have a better idea than that, feel free to let me know. As far as I know references are the only way to access a control that may be changing once you've already entered a subVI.
    Thanks for the tip on the event structure, I'll give that a shot tomorrow.
    Yes, refs are the only way to control front panel objects from another vi, but do you need to? Send the value to the checking vi and react to that, if need be return a Valid boolean or similar, that's how it's usually done.
    /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

  • While loop in xpress

    Hi,
    I have retrieved a list of users. Each user having some attributes like manger id, user id, location. I have stored the result in one attribute named 'test'. Now i want to create a while loop so that each user is fetched and all the attributes of eaach user are getting fetched.
    i have done the search on th basis of firstname and last name..here is the code
    <set name='test">
    <invoke name='funcname' class='classname'>
    <ref>fname</ref>
    <ref>lname</ref>
    </invoke>
    </set>
    now i want to start a while loop using this
    <ref>
    <concat>
    <s>test[#</s>
    <ref>i</ref>
    </s>]</s>
    </concat>
    </ref>
    please tel me what should be the code for while loop so that all the entries are fetched for each user

    Hi princy,
    Can you tell me how are the attributes stored in each user?
    Here test variable is a list,where each element of list represents a user.Now how attributes Like manager,location stored in it?can u clarify tht?
    Thanks.

  • 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 a while loop with a interrupt

    I' m using a while with a delay time of 60 seconds to perform a sub vi.
    So when I press the stop button it could take in extrem 2 minutes to stop the vi. I want to use something like an interrupt or jump order to stop the vi without waiting for the end of delay time.
    How can I create an interrupt in lab view 6.1.
    Thanks for help. bye uli

    If the delay is in the calling VI using Wait (mS), you can run a smaller delay multiple times (a while loop inside your main while loop), checking Stop between each of the smaller delays until the smaller delays add up to your bigger delay. See the attached DelayWithStopCheck.vi.
    But this technique doesn't stop the sub-VI: it just stops the loop in the main VI which will still run until the sub-VI is done. You could connect the Stop button to a global which the sub-VI checks in a loop to know if the calling VI pressed Stop.
    Attachments:
    DelayWithStopCheck.VI ‏41 KB

  • Random delay between WHILE loop during acquisition from DAQ

    I am working with the NI DAQ USB 6259.
    My purpose is to acquire data from an analog voltage input. My problem is showed in the attached image and consists in a RANDOM time delay between the execution of two consecutive while loop that contains the acquisition and the writing operations.
    If you observe the image attached, you can notice that samples are taken at regular interval (which I can specify) only within one loop, then between the instant of the last sample of one  cycle and the one of the first sample of the next cycle, a random delay occurrs.
    I attach also my block diagram which is very simple.
    I am forced to use the option "N samples" in the daq assistant because if I use continuous acquisition an error is returned, I guess because my acquisition can last minutes.
    It's like I were blind for a random duration between consecutive iterations of the while!
    Do you know an alternative solution to avoid this problem or its solution?
    Best regard,
    Roberto Rodio
    Attachments:
    while loop delay.jpg ‏52 KB
    block diagram.jpg ‏42 KB

    Have you tried to execute this without the writing to the TDM file?  I suspect that is where your delay is happening... So I propose you delete that from your block diagram... and execute your loop... if that works, you will need to move your file write to somewhere else in the process... possibly a parrallel loop... If not, consider stripping down the express VI you use for your data acquisition... The delay could be in that express... setting up, starting, acquiring and stopping the daq task... In which case, you can right click on it, say open diagram... or open vi or something similiar... LabVIEW will tell you that it must convert the VI, so OK (you can alway undo)... I am not sure what else you have going on... so you may already be doing that... but that is the first two places I would look.
    Paul <--Always Learning!!!
    sense and simplicity.
    Browse my sample VIs?

  • 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

  • How can I put a time delay between specific events in a while loop?

    How can I put a time delay between specific events within the same while loop? I'm already using the "wait" command to control the overall loop iteration speed. But I want to time the individual events as well.

    Hi Jesse,
    You can use a flat sequence. In each box you can put your individual events and attached wait.
    Don't forget to reduce your total loop time of the time you added in the individual sequences.
    Doc-Doc
    Doc-Doc
    http://www.machinevision.ch
    http://visionindustrielle.ch
    Please take time to rate this answer

  • Use the LabView time delay in a while loop instead of using the instrument inherent time loop.

    I have a zes lmg500 that I use. It has the option of continues measuring data, with a user control cycle loop (still using a while loop but the delay is coming from the instrument). The problem is that the loop time is not constant. Can I use a very short time (100ms) as the instrument cycle time but use a longer time delay in the while loop that collect the data?
    I know many instrument offer the same abilities, so the question is relevant to all of them.
    Thanks for any help
    Solved!
    Go to Solution.

    Does that measurement VI have built-in wait functionality and a timeout?
    If not, then you are simply polling the VI at 1 kHz, but I suspect that this is not the case or your Waveform Chart probably wouldn't look as you expect (getting 0's put in everytime measurement data is not available).
    I expect that if you have the instrument set up to send data at a fixed time interval (i.e. 100 ms), all the data that it is sending you will end up residing in your serial buffer (or the instrument driver will have taken it out and put it in another internal buffer), so if you come back to read it 1 sec later, then you will have 10 data points to go through.  Whether you can read them all at once with the read VI or have to call it a whole bunch of times until empty I can't say.
    What is your objective?

  • How to stop a while loop with long delay

    Hi everyone,
    I am building a simple program for turning on and off a single Bit.  The task is to turn ON the Bit for a period length T1, and OFF the Bit for a period length T2. T1 is normally different from T2, and can be controlled  by users. 
    Since T1 and T2 can be variable, they sometimes can be very long.
    If I use a Wait function inside a While loop, it needs long delay to be able to Stop the Main program.
    The same situation happens when I use Timed loop.
    Can anyone suggest me how to do this task?
    Thanks a lot. 
    Message Edited by tatuan on 04-12-2010 12:56 AM

    Here's another possibility using OpenG Wait ms:
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

Maybe you are looking for

  • Cleaning virus-infected files on external hard drive used for Time Machine

    I am kinda reposting this with some extra explanation since I didn't really get any good respnses on my first post: I am running McAfee VirusScan and it locates and cleans virus infected files just fine on my computer, but when it finds infected file

  • WD My Book 2T Model WDBF JK0020HBK-NESN compatibility with Mac OS 10.5.8

    Apparently WD Tech Support declines to answer the following query. Does anyone know the answer? Thanks I've discovered that the new My Book 4T drives that I'd planned to used with my iMac running OS 10.5.8 are not compatible with that OS. I've got My

  • Hyperion 6.1 with Windows 2003 SP2?

    We are trying to upgrade our production servers from windows 2003 SP1 - SP2. These server have Hyperion 6.1 installed on them. I just wanted to know if this would have any impact this version of Hyperion. I personally wouldn't have thought so but I j

  • Applet i/o

    Java applets cannot read or write files, this is a fact. but can the java applets use class files to read/write to a file? for example..... creating a counter in java is theorethically impossible for use as an applet counting the number of hits on a

  • Is Photoshop elements compatible with Mountain Lion?

    Is Photoshop elements 10 compatible with Mountain Lion?