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

Similar Messages

  • Can anyone tell me what's wrong with my queue or producer consumer loop?

    A Labview engineer helped me with the overall structure of my program, necessitated by the fast data sample rate and post processing requirements. He recommended the producer/consumer loop and using one of the example files (Cont Acq graph voltage - int clk) to do the actual data acquistion. So I put together the loop and go my two channels of data acq going in the producer loop. However, nothing's getting picked up in the consumer loop and none of my data gets displayed over there.
    Anyone care to take a look at it and let me know what I'm doing wrong?
    Solved!
    Go to Solution.
    Attachments:
    P-C Yanmar Program.vi ‏296 KB

    Your Enque Element should be inside the while loop where you aquire the data.  As it is now, the data has to stop being aquired before you send the last set of aquired data.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Producer consumer loop for serial comms

    I have an application where I am trying to read and write to a serial port using a producer consumer loop.  My producer consumer loop seems to work fine until I put the serial comm VIs in the consumer loop.  Prior to that my event structure in the producer loop seems to work fine and all the controls on the front panel send commands into the queue and the expected reaction happens in the consumer loop.  When I put serial comm VIs into the consumer loop the application will read the serial port but none of the other controls on the front panel ever get any reaction from the consumer loop.  I am not sure if I am using the producer consumer loops correctly when using comms at the same time.  Any help would be appreciated!!
    I have attached the VI for your inspection.
    Attachments:
    pinger comms.vi ‏65 KB

    You could probably continue with your original architecture as well.  Just put the check for bytes at port in the Read case of the consumer loop.  As you said, it takes 1-2 seconds for the device to send data.  So the original architecture didn't work because you were queueing up 20 reads per second in the timeout case, but the consumer loop was taking up to a second for a single byte to come in.
    If you check for bytes in the consumer loop, if none are there, the Read case will end quickly and won't wait for that byte to come in.
    You should also probably increase the timeout of the event structure to 100-200 mseconds or even more.  The event structure would still respond instantaneously to user interface events.  And you would only be generating the timeout case a few times per second.  Which means when a byte comes in, it would probably be sitting there only 100 mseconds or so before you read it.  Unless you go click happy and generate lots of other  events not allowing the timeout case to run.

  • Producer consumer loop

    I have a Producer consumer loop that is  reading in data from a Excel File call sample1. There is a third party software that constantly writes data to the same excel file Sample1 every _ amount of seconds. Every time the Third party software writes it will over write the excel file data. So it may only be 5 columns and 3 rows.
    1. I need to make sure that there is not a conflict when the Third party software has the file locked to read and Labview is trying to read.
    2. I need to make sure  that if labview isn't reading and reading before the Third party software writes so basically i need some way of checking labview isnt reading the same data twice i need to make sure the file has been updated before it tries to read again. The problem comes in when you can't regulate the time that the third party software reads.
    Solved!
    Go to Solution.
    Attachments:
    VI snippet (2).png ‏123 KB

    I've had to write code for similiar applications.  It is tricky.
    Have a look at the .NET FileSystemWatcher.Changed Event.  This might be a good way to monitor what is happening with the file.
     Take a look at this post: http://forums.ni.com/t5/LabVIEW/My-First-Nugget-Directory-Changed-Event/m-p/1407552/highlight/true#M...
    "There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal

  • Data delay in producer consumer loop?

    Hi,
    I've been creating an VI using producer consumer loop. In producer loop, every loop take 1000 samples at the rate of 40000/s(or 40000s/s devided by number of channels) and the consumer loop will average the data in a way corresponding to the "sampling rate" value on the front panel. The "sampling rate"represents the data rate on the chart and in the saved data file. If it's too slow,say 1 sample per second, then the producer loop will just wait for some time.
    So far the VI run smoothly, but there's one big problem. Each time I adjust the amplitude of input signal and the change doesn't show up on the chart untill several seconds later. When the "sampling rate" is really slow, the delay could be 1 minute! It's the first time I have ever used producer consumer loop and I 'm really confused of what causes this time delay.
    Could someone give me a hand with this?
    Thanks!
    Yaqiong
    Attachments:
    parallel.vi ‏73 KB

    You should consider further separating your tasks. For instance, the writing to file should be in its own task since file I/O can really cause delays in your processing. Also, I would separate your data processing (averaging) from the UI updates. The UI updates can be within a task that is using an event structure. It can get the data updates to update the chart but it can also quickly respond to the changes in your amplitude. I would also be very careful of the wait in your producer loop. This could starve the CPU.
    One last note. Your code could really benefit from a cleanup. Your coding style is quite a mess and it makes reading (and maintaining) your code much harder. For example, your code should generally read from left to right. Running wires backwards, having outputs on the left, lots of bends, etc all lead to messy code that is difficult to read.
    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

  • Basic Producer/Consumer loops for a newbie

    Labview neewbie here.
    I was looking at Producer Consumer loops.
    Can anybody give me a very basic explanation of how to set one up.
    I want to take readings from a HP 53131A counter and store them in an excel spreadsheet.
    I understand the part about labview slowing down as it opens the Excel file, and a seperate loop will help solve this.
    But I dont understad how to set up the Que function.
    Thanks.

    Multithreading will not make excell open faster but using concurrency you can have more than one operation operate ate different speeds.  The nice thing about the produce consumer model is that the if the consumer is slow or unreliable (freeses up) the producer doesnt care and will continue.  To use a queue is very simple, 1. create the queue, name it(optional) and give it a data type (ie int, array of floats ...)  in the produce loop use the enqueue vi to add items as needed to the queue, in the consumer dequeue these items (using a timeout = -1 the loop will wait for a new item and not consume resources)  the consumer can process the data acquired in the producer loop.
    Paul Falkenstein
    Coleman Technologies Inc.
    CLA, CPI, AIA-Vision
    Labview 4.0- 2013, RT, Vision, FPGA

  • Synchronizing 2 graphs / producer-consumer loop stuck

    I have a pretty huge VI here, so I created a smaller one, which shows my problem.
    First thing is, the user has to set some parameters, before the VI is running. So, I created a sequence with a while loop. If the user hits the button, the loop ends. That works pretty well.
    In my huge VI I am doing data acquisition. The user hits the button in order to acquire data, checks the data and the data is saved when he hits the acquire button the next time.
    Next thing is, I have two graphs. When the user zooms one graph the scale of the other should be updated automaticaly. Therefor I created a loop with a event structure in it. If the user hits the button in order to acquire the next set of date, the loop ends. So far so good, this works pretty good as well.
    But now - if I zoom the graph before I hit the button in order to end the while loop, everything gets stuck. I don't know how to get rid of that behaviour.
    Please do not suggest anything like getting rid of the producer/consumer loop, since I specifficaly need everything that is in the VI for a certain purpose.
    If you need any additional information, please just ask. I hope my problem is described well enough so far.
    Attachments:
    zoomprob.vi ‏41 KB

    thanks for the response,
    the upper event structure will trigger the data acquisition process, so I don't want to have any time out value unless the user wants to start the acquisition process.
    the lower event structure will take care of the state when the acquisition is done, but the user wants to examine the aquired data. Using a longer time out will not be a disadvantage, but I think it will not solve the problem alone.
    At the moment everything works fine, if you use it how it is ment to be used. If you aquire data and then mess up with the graphs scale, everything is good. But if you try to manipulate the graph and then acquire data, it gets stuck. Apperently, that is not how it's ment to be used - but you know what users often do...
    Unfortunately the highlight execution is of no particular use. If I turn it on and manipulate the graphs scale, the vi gets stuck, but no specific process is shown in the code. Apperently it is waiting for a event, but it isn't triggered. So, beeing able to disable an event structure and enabling it later would solve the problem, for example.... I haven't found any solution for dealing with that, unfortunately...

  • Producer consumer loop array building

    Hello,
    I am trying to build an array in the consumer loop of a queued vi. This is the first time I have tried to use a producer-consumer structure since class many months ago. Each element is queued and sent to the consumer loop, and in that loop I want to build an array of the elements before I save it to disk. For some unknown reason I am having trouble accomplishing this. Usually I throw this stuff into a for loop, but here it isn't working.
    I am converting the random number to a string in the producer loop because when I build the real program I will be using strings.
    What am I missing?
    Tay
    Attachments:
    Loop test.vi ‏35 KB

    Just built your array in a shift register.
    (The error case is simply wired across.)
    Message Edited by altenbach on 05-16-2008 08:03 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    looptest.png ‏8 KB

  • Stopping producer consumer loop at the same time

    In my application I am using producer consumer architecture. In the producer loop, I am acquiring data, processing and outputting the result (feedback control system). Also in the same producer loop I am inputting all the data to a queue and then in the consumer loop I am writing data to a file. I have a stop control on the front panel and error from the queue and  error from the data acquisition all wired to OR gate to stop the while loop. ( I attached the picture of the code). Whenever I press stop form the front panel program wont completely stop. I think it is because consumer loop still running. Is there way to stop  the both loops at the same time. I tried creating local variable but it slows the program. Front panel stop control mechanical action is set to switch when released.
    Attachments:
    app.PNG ‏262 KB

    In the consumer loop you should check the error after the Read Queue function.
    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!

  • Producer loop and 2 consumer loop for acquisition and process images

    Hello everybody,
    I'm quite a newbie in Labview 2011 on Windows 7.
    Those are what I want to do :
    Step 1: When the objects fall with velocity around 2 to 5 m/s, images of these objects will be acquired continuously from PCIe 1433 with Basler spL4096-39kc.
    Step 2: The processing of the images continuously in the same time with step 1 will find the datas of the objects in images as colors, patterns and locations. If the patterns and colors at location are as the same sample, the elements in Boolean data array are true.
     Step 3: Every 01 millisecond, values from Boolean data array will be read, the valves of nozzle will be opened if the values are true.
     My question is what is the best way to do my tasks ? I couldn't find any example of program in Labview and I think I use producer/consumer architecture for step 1 and 2 but I don't know how can I set up producer loop for step 3 and transfer Boolean data array from step 2 to step 3 ?
    Thank you for reading and help me !

    Dear Eric-J,
    Thanks for your reply. I want sort the pellets that have 6mm diameter. The pellets were fed in a single layer by a vibratory feeder with a flat-bottom trough, 400mm wide that was supplied with the feeder . The pellets dropped off the end of the feeder onto a chute with 40 parallel U-shaped grooves. Images of these pellets will be acquired continuously. I make the sample from image that was acquired. I use NI Vision for processing  of the images. If the patterns and colors of pellets are as the same sample, the elements in boolean data array are true. As you thought, I would like to interpret data every millisecond and open/close a valve based on the boolean array. The air valve sends a burst of air for 2 - 3 milliseconds to an air nozzle that diverts the pellets into the appropriate channel.
    What are your ideas for this task ? Could you explain more clearly about "a real time system" and "determinism" for this task ?
    Thanks and best regards

  • Producer consumer loop only execute once?

    Hello here,
    In my VI, the producer loop seems working continuously, but the consumer loop only execute once.
    I haven't used producer/consumer pattern before, could someone give me some ideas why this happens?
    My code is in attachment.
    Thank you in advance.
    Yaqiong
    Solved!
    Go to Solution.
    Attachments:
    parallel - Copy.vi ‏72 KB

    That would be the poor choice of using an event structure in the consumer loop.  As set up you must generate a mouse Leave or mouse enter event on Waveform Graph for the consumer loop to finish its first iteration. 
    Delete the event structure.  you don't need it to update a graph.
    Jeff

  • Generate dynamic event of producer loop in multiple consumer loop

    I have one producer loop which used event case to interface with FP controls and 5 consumer loops
    If I have to use the fifth consumer loop to generate dynamic event which send to event case in produer loop. 
    I have to wire register event with dynamic event terminal in producer loop . Also I need to wire user event to consumer loop (at the bottom of screen window) which is far away from producer loop. It is hard to wire them. 
    Is there any other method to let many consumer loop to communicate with one producer loop through dynamic event (the same user event)?

    I like to use an Action Engine to hold control my Event Reference.  Then anybody can send the event commands.
    You may also want to look at the VIs I recently submitted for OpenG here.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Can't terminate while loop in producer/consumer

    I have attached a simple vi that was constructed from the producer/consumer (events) template.  In the vi I have set up a counter.  I want to be able to terminate the counter when the stop button is pressed.  This doesn't work as planned.  The counter goes to its full count before the program stops.  The vi does work as planned when run in highlight execution mode.  Can't  figure it out.
    Thanks in advance.
    Solved!
    Go to Solution.
    Attachments:
    ProducerConsumerEvents 3.vi ‏14 KB

    You can set the stop button to latch action and place it in the lower loop. No local variables needed.
    The event will fire right away and the lower loop will reset the button once it's read. No race condition possible.
    (Personally, I would probably redesign from scratch....)
    Message Edited by altenbach on 08-10-2009 11:33 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ProducerConsumerEvents 3MOD.vi ‏13 KB
    ProducerConsumer.png ‏23 KB

  • Consumer loop slowing down producer loop

    Hi All,
    I'm currently using a PXI to send commands to a chip, then retrieve the results with a DAQ. This process loops to populate a 256x50 array of values.
    Each time the loop is fully populated, I want to display the result onto a 3D plot, using 3d plot lvclass and plot helper. I noticed through the profiler and using timing functions in the loop that the 3D plot would take ~200 ms to update. The array would fully populate in about 100ms, so tripling the time to update was kind of nasty.
    I put the 3d plot into a consumer loop and everything else in a producer loop. It works fine, I don't mind about dropped frames, but it was running at the same speed. Apparently whenever the consumer loop executed, it would freeze completely the producer loop.
    Why is this? It seems like this fellow had the same problem:
    http://forums.ni.com/t5/LabVIEW/Producer-Consumer-Loops-not-independent/td-p/1115665
    But he "solved" it by removing the graph altogether. As showing the graph updating in real time is critically important, I can't just chuck it.

    No, an action engine is sometimes called a LabVIEW 2 Style global. They are basically a VI with a while loop and an unitialized shift register. They are useful when passing large amounts of data since it does not get copied. Also if you have transformations that are made on the data it is a single self contained VI that has data and actions which can be performed on it. Today a LVOOP implementation would be prefered. At any rate, this is a non-reentrant VI which will cause blocking to occur if called from two or more loops at the same time.
    Out of curiosity, what type of graphics card do you have in the PC? Would a better graphics card help?
    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

  • How to end consumer loop

    I am using producer/ consumer pattern to separate data acquistion and processing. The consumer loop is much slower than the producer loop. If I put "release queue" outside of the producer loop to stop the consumer loop, the consumer loop can just run once. But I need consumer loop to run same times as producer loop. So I did not use the release queue to stop the consumer loop but used the error connecting with  "stop if true" in the consumer loop. The producer loop and consumer loop are in a sequence structure. It seems that the sequence contains producer/consumer loops can never finish to enter into the next sequence. I think that producer loop and consumer loop have all stopped because their iteration numbers stop increasing at certain time. But the vi can never go into the next sequence. So I am very confused about that. If I put "release queue" outside of the producer loop to stop the consumer loop, the vi can finish this sequence and go into the next sequence. Do anyone know how to solve the problem?

    Sophia,
    The idea of passing the stop command via the queue is that it will be at the end of the queue - after all the data.  The consumer loop will see the stop command after it processes all the earlier data. In this case it might be better called "End of Data" rather than "Stop." 
    The sequence structure is totally unnecessary.  Use dataflow to handle the initialization and  completion code.  The sequence structure will definitely proceed to the next frame when all the code within the current frame completes execution.  If the iteration counts have stopped increasing it may mean that the loops have stopped running or that the producer is blocked, waiting for something within it to finish so it can go to the next iteration.  It is also possible that the consumer loop has started an iteration but no data is in the queue.  Since the timeout is default at -1 the Dequeue will wait forever for data.
    Please look at the style guides.  Use left to right wiring and avoid hiding wires behind other objects.  Also try to keep the diagram to the size of one screen.
    Parallel loops should always have some kind of wait or delay to allow CPU resource sharing.  In the producer loop the data acquisition VI may provide that function.  In the consumer loop the easiest way to get a delay would be to change the Dequeue wait time to something other than -1.  You also should check the Dequeue Timed out? line if you use timeout for the delay.  If it is true, then the data is not valid and should not be analyzed in the for loop.
    You probably only see the last of the 10 spectra. Unless the datasets are rather large, the loop will probably run too fast to see the others.
    Lynn 

Maybe you are looking for