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

Similar Messages

  • How to change the transmissi​on rate of data flow in producer/ consumer pattern

    Hi All
    I am new to labview and trying to design a application to transfer image data in different rates, that means I can change the transfer rate in the transmission process. In fact,I refer to the the Queue Basic.vi to achieve this function by Changing the delay value of dequeue and enqueue.The program is divided into three parts:
    The first part is the sender in vc used to split and send image data.Data size is 226kb and each time we send a 1kb packet;
    The second is labview rate-change part,use producer/ consumer pattern and queue to transfer data;
    The third one is the receiver in vc,receive data in sequence and synthetic images.
    The entire transfer process is: image data was sent from the sender to producer loop through DLL, then enqueue--dequeue in consumer loop--DLL--receiver.The sleep time in vc sender is equal to the delay value in producer loop and this makes it look like the data generated as in the loop.
    Now this is where my dilemma is:
    When transferring data, if the producer loop and consumer loop delay value are equal(both 20ms), I can see image synthesis at a constant speed and no data lose; if I change the consumer loop delay value and make it greater than the producer delay(one is still 20ms and another is 50ms),that means receive in a lower rate and store data in queue. I can see Elements in Queue
    increase but the image data randomly lost, and the image synthesis speed is not reduced.
    My question is why image data loss and I can't see the image synthesis speed reduced when change the delay value in consumer loop?
    Do anyone know how to solve the problem? Are there any examples I can refer to? Any suggestions are greatly appreciated!
    Attachments:
    image1.JPG ‏56 KB

    thisoldman,
    I don't have '/usr/lib/modules/3.17.3-1-ARCH/build/Documentation/VGA-softcursor.txt' on my file system. Does it contain the info about changing the blinking speed?
    P.S. The other two links I found yet before starting this thread. I only found in them the recommendations about changing "the color and shape of the cursor and turning blinking on/off" (as I mentioned in the original question). Did I miss the info about the blinking speed?
    PPS: I found the vga-softcursor.txt here: https://www.kernel.org/doc/Documentatio … cursor.txt
    But that file doesn't tell about changing the blink rate either.
    Last edited by nbd (2014-11-23 20:55:41)

  • 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

  • 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

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

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

  • 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

  • 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 

  • Input and output on same device, producer/consumer structure

    Hello interested people,
    I have a question about using the same device for both digital inputs
    and outputs.  I have written a simple program of one while loop
    that continuously polls the device, processes, and requests.  I
    have addressed the device using two DAQmx Asst. and I have attached
    them with their error in/out cluster terminals to provide data flow and
    eliminate the chance of addressing the devices at the same time (which
    produces an error).  Now I want to change this program structure
    to a producer/consumer loop foundation with state machine.  
    In this design, I will have the DI in the producer loop and the DO in
    the consumer loop, under one of the states.  I can't simply
    connect the error in/out ports in this configuration, so my question is
    how to avoid the error caused by addressing the same device
    simultaneously with two different tasks (input and output)?  I
    have attached two VI's, the "One Loop" vi is the original configuration
    (simplified), and the Producer-Consumer vi is a NONSENSICAL program
    that simply represents the desired configuration.  (I don't need
    any comments on the programming of this vi, it is only an example for
    illustration of the problem). 
    I am thinking about bundling the input data and the error cluster, both
    from the PXI 6528 DI, into one cluster, queueing that up, and
    unbundling the de-queued elements for some kind of data flow between
    the producer loop and the "Request" state of the consumer loop. 
    Is this the right approach, or am I barking up the wrong tree?
    Thanks
    Attachments:
    One Loop DO DI.vi ‏102 KB
    Producer-Consumer DI-DO.vi ‏106 KB

    Hello,
    It sounds to me like you really have two modes:
    1. user interface actions determine execution
    2. user interface is locked, and execution is automated.
    I think it would make sense to use the producer consumer for an architecture.  Basically you would do the following:
    1. program the producer to handle the user interface as you normally would.
    2. provide one additional event case in the producer which would be your "automated handling" case.  In that case, you could put a state machine which could run until whatever conditions were met to put your program back in "user interface mode".
    Keep in mind that you can use custom USER EVENTS to programmatically generate events ie. you can trigger the start of your "automated handling" form anywhere in your code at virtually any time.
    I think this would allow you to take advantage of the producer consumer architecture in its intended spirit, while integrating an automated routine.
    I hope this helps!
    Best Regards,
    JLS
    Best,
    JLS
    Sixclear

  • Producer/Consumer Architecture

    Hello All,
                    I am currently working on an application using State Machine Architecture where I have to monitor various parameters (7 temperature values & 3 pressure values), along with this I have to On/Off a Clutch using a digital Output for set time (e.g. On for "X" seconds OFF for "Y" seconds), but as soon as the pressure and temperature values go beyond upper or lower limits or whenever the user presses the Emergency Stop (that means I have to monitor Digital Input as well) so I am moving to different error cases depending on which values go beyond limits or emregency pressed etc..
                But this realisation is not working fine as I have to monitor and control several other things in addition to acquiring data....till now I just have used State Machine Architecture, I have seen Producer/Consumer Template but not quite sure how to realise such kind of application which involves data acquisition along with user interaction and monitoring.
    Could someone please put some light on giving similar kind of example or what else I can try with this problem.
    Regards
    James

    Hello James,
    A Producer/Consumer architecture will certainly do the trick for you. I am sending you an example that has the Data Acquisition section in the producer loop. However, you can also put your User Interface in the Producer loop and have the Data Acquisition in the Consumer loop. The Queues are used for sending data from the Producer to the Consumer(s) loop(s) (you can have multiple comsumer loops).
    You will just have to design specific cases to react to different user inputs.
    By the way, this example is from LabVIEW Basics II training course. If you have never taken LabVIEW Basics I and II, I highly recommend them. You can self-pace the class or take it with an instructor.
    LabVIEW Courses
    Hope this helps!
    Message Edited by Kalin T on 03-23-2007 09:57 AM
    Kalin T.
    National Instruments
    Attachments:
    ImplementedProducerConsumer.zip ‏250 KB

Maybe you are looking for

  • Sound does not work correctly all the time, on youtube.

    So I have been having this issue for a while now, and I have tried everything to fix it on my own. My issue is sometimes you-tube videos will play about 1-2 sec of sound then stop, the video will buff all the way out and I can watch it but no sound w

  • JQuery slideshow doesn't work

    Now that I have the javascript code in the right place in the head, and I have followed all the other instructions to get a jQuery slideshow into my webpage, are there any ideas why it doesn't function as a slideshow please? In browser preview, one p

  • Is it possible to restore from a backup after initial setup on my iPad air?

    is it possible to restore from a backup after initial setup on my iPad air?

  • Not Random - iPod plays same named songs in a row

    I have noticed that the iPod on shuffle mode isnt entirely random. It plays all songs with the same name in a row. I notice this frequently as I have singles, studio albums and live albums on my iPod. Whenever it randomly plays song XYZ, if there are

  • Why the 10.4.6 update doesn't recognice my HD?

    I'm trying to install this update and i get stuck on the "Select a Destination" window, where my HD is marked with the exclamation mark in the red dot thing. With a message "installling this software requires 183mb of space" (when my HD have 112GB fr