LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

flushing element in queue

Solved!
Go to solution

i am trying to flush element in my queue and save all the elements, it has been hours I am working to find a way but it is not working. any idea how to do that?

 

the output of flush is attached to this post

 

 

0 Kudos
Message 1 of 23
(8,080 Views)

Can you describe more carefully what you are trying to do? 

 

When you flush a queue you remove all the elements from the queue and they are returned as an array. You cannot "flush" just one element from a queue (unless it only contained one element at the time you called Flush).

 

When you say "it is not working" please be more specific. Does the queue not get flushed? Do you get any errors? What are the error messages? Are you sure the queue has data in it when you call Flush?

 

Please post your code with some data saved as default or specific instructions on how to operate it to create the issue you are having.

 

Lynn

0 Kudos
Message 2 of 23
(8,071 Views)

Hi Lynn,

 

Please see the attached file, how can I save all of the data at once (when click stop buttom)? I know I can use deqeueue to extract the data, but I need to use flush. 

0 Kudos
Message 3 of 23
(8,066 Views)

You can try this method to read all the data and write it to a file.

FlushData.png

 

-----

The best solution is the one you find it by yourself
0 Kudos
Message 4 of 23
(8,037 Views)

Thanks, I found a another way to do that. and realized that there is basiacally no difference in time to flush a large number of data using flush queue or extract them using dequeue. 

 

I realized that my problem is another thing, my consumer is very slow!

0 Kudos
Message 5 of 23
(8,035 Views)

I've never felt the need to extract something in a queue by doing anything but dequeuing it.  Perhaps your consumer is slow because you are using queus in an unintended manner?  The fact that you felt a need to grab the data out of the queue all at once would suggest something like that.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 6 of 23
(8,009 Views)

Here is one way to clean up your VI. Queue-2.2.vi

 

Often it makes more sense to write to file less frequently and to write larger chunks each time. I would probably simply keep track of the amount of data in the queue and then flush and write. when I reached the desired size. Or as BIll said, dequeue as the data arrives, accumulate in a shift register and write when appropriate.

 

I see you appeared to have a problem connecting the Flush Queue output to the Array to Spreadsheet String  function. This is because Flush Queue returns an array of clusters of array. Why does it do that? It cannot use a 2D array because arrays must be rectangular. The queue has no way to know in advance that all the arrays fed to Enqueue will have identical lengths. The cluster of array allows variable length arrays to be enqueued. This is described in the Detailed Help for the queue functions.

 

I have also included a somewhat simpler VI which does the same thing as your VI attempted to do. It uses no queue and no notifier. Queue-2.3.vi

 

Lynn

Download All
Message 7 of 23
(7,994 Views)

Hi Bill,

 

You areright! my consumer is very slow and I thought maybe flushing all the data from the queue at once is the solution. but the problem is, I have a large amount of data and even flushing them, takes almost the same amount of time comparing to dequeueing them. the code that I attached to the previous post is just a simple example I made to undertand how queuing works. 

0 Kudos
Message 8 of 23
(7,975 Views)

Hi Lynn,

 

thanks for the clarification about the flushing queue and also the codes.

 

I understand, what you mean by reading a large amount and then write them to a file. let me explain my case in detail:

 

I am reading samples from a FIFO. when number  of samples reaches 51200 (which is my sampling frequency), I transfer all of them into a queue (using enqueue block)

 

then I save all of these 51.2 Kilo Samples using dequeuing and write to txt file (I have tried write to binary too, but didn't solve the probelm). 

 

Now the problem is:

 

the producer, is much faster in reading 51.2K data than the consumer. so what happens is, after some time (let's say 10 sec) I have read 10 block of 51.2k samples, and only dequeue 1 block of 51.2 k samples into file. So, when I stop the code, I have to wait until all of the 9 blocks of data pass the dequeue block and save to file. 

 

maybe 10 block isn't that much, but when I am saving for 2 minutes and there are 75 blocks in my queue, I have to wait maybe 10 minutes to save all the data (I am just making an example, the numbers aren not accurate). 

 

that is my problem, I have a feeling , maybe there is no other way to solve this problem!! 

0 Kudos
Message 9 of 23
(7,971 Views)

From the numbers you just provided you should be writing once per second.  That should not be  a problem.

 

Can you post your actual code? There may be something else in there which is slowing things down.  The consumer loop should spin as possible if there are multiple elements in the queue.

 

Also consider the TDMS files. They are optimized for writing speed.

 

 Lynn

0 Kudos
Message 10 of 23
(7,965 Views)