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.

Similar Messages

  • 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

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

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

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

  • 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

  • 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

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

  • Timed Loop in Producer/Consumer Loop

    Hello!
    I have a producer/consumer loop LabVIEW program setup to allow me to properly capture images that are quite large (8MP) at approximately 14 frames per second (FPS). The program works great when the consumer loop is a 'while loop' (records at 14fps no problem), but I wanted to make it into a timed loop, so that I may vary the FPS as required. An oddity arises when I do this. Anywhere below 12fps, the loop works fine and the data is recorded properly. However, when I bump it up to 13fps, the consumer calculated FPS goes haywire and starts jumping between ~9 and ~13fps (data processing gets bogged?). When I set the required FPS to 14, the loop executes at a steady 7FPS maximum. Is there something I can do to rectify this situation?
    I have attached my .VI
    Thanks in advance!
    Solved!
    Go to Solution.
    Attachments:
    ProcessSplitJPG-FPS.vi ‏100 KB

    Palanski,
    Are you using LabVIEW Real-Time? Timed loops in a windows OS don't really increase determinism more than a while loop with a wait until next multiple timer. Before you changed the producer consumer loop to include a while loop was the programming running correctly? You may also want to vuse the VI analyizer to see how long things are taking to run. I would leave the producer consumer loop in the traditional set up and change the FPS by controlling the wait timer, after benchmarking your code this should be done the same way as you have it for the timed loop
    Sam S
    Applications Engineer
    National Instruments

Maybe you are looking for

  • SOAP response in attachment - how to transfer this to ERP via XI adapter?

    Hi all We have a proxy <-> PI <-> WS scenario We use "Do not use SOAP envelope" in order to create a specific header info for the WS. The reply from the WS puts the response (xml) in the payload attachment. Everything is ok in PI But the generated pr

  • Eyedropper tool with masks in Illustrator CS4

    When I sample a colour from a masked object in Illustrator CS4 it doesn't sample the colour correctly. It looks like it's doing it optically rather than using the exact colour breakdown I have assigned the colour. It doesn't even look like the same c

  • Has anyone else had this problem Viewsonic 19" VA912b "Out of Range"

    I bought 2 new Viewsonic VA912b 19" flat panel monitors and found that when I tried to boot the computer from a CD (both a G4 and G5) running OX10.3.9, the screen would go black then display the message "out of range" then go totally black. The only

  • Update Photoshop CS3 Extended 10.0 to 10.0.1

    I try update 10.0 to 10.0.1 I uploaded http://www.adobe.com/support/downloads/detail.jsp?ftpID=3794 When I run PatcherApplication I have info that INSTALLATION WAS UNSUCCESSFUL THE UPDATER IS UNABLE TO LOCATE THE PRODUCT TO BE UPDATED why ? Could any

  • HP Laserjet 1300 nouveau pilote avec Win7 64b

    Mon imprimante laserjet 1300  ne fonctionne pas avec Windows 7 64b, j'ai téléchrgé un pilote universel et ça ne fonctionne pas. S'il vous plait, indiquez-moi quel pilote je dois télécharger. Merci de votre attention