LabVIEW Channel Wires

cancel
Showing results for 
Search instead for 
Did you mean: 

Flush Stream Missing (?)

Moving the conversation over from the LabView discussion forums. I'll copy and paste some of the original question(s) I had in that duscussion below:

I've been playing with the new stream feature in LV2016 in place of a queue. I have noticed a glaring omission. There is no flush stream capability. I find this function invaluable when building any type of queue if I wanted to dump all data in the queue at once. Case in point, I'm sampling data from a ADC into a queue. Then in another process I'm reading that data. I want to change the sample parameters and then start reading again. I need to flush all the data in the queue with the old sample rate (or whatever) when I reprogram the new settings.

Apparently this can't be done with a stream. I can't even do a read multiple (get an error code 1059) when I try and create that function while having a read or write (single) stream.

Instead of Flush Queue, I tend to use a FOR loop or While loop to dequeue the elements until it is either empty or I have read X data points.  What this does is avoid the memory reallocation from flushing the queue (which actually deallocates the memory) and then building up the elements in the queue.  I imagine you could do the same for the Stream Channel.

My Response:

I thought about doing that. But nothing is free. The 2 issues I see with this method are 1) it requires another parallel loop running in my code dequeuing and processing data that I don't need. (Not really that big of a deal other than having to rewrite the code I already have - I may do this anyway.) But more importantly 2) there is sometimes a delay in the data due to the queue filling up because of fast sample rates and the amount of processing I am doing to the data. My computer doesn't quite keep of with the processing. So whenever I want to change parameters that I'm testing. The data in the queue is of the wrong sample rate and my program errors out. Waiting for all the data to clear out of the queue could be as long as 5-6 seconds in some cases. IMO it is much better to flush the data in a single cycle and start with new data whenever I need to change parameters.

Maybe there is a better way to accomplish this task that I don't know about which is why flush stream wasn't included in the initial release. All the other methods I can think of requre more overhead and passing more variables between parallel loops vs just stopping the ADC, flush the queue (stream), reprogram the ADC, start the ADC - and not having to pass anything to the stream read loop.

0 Kudos
Message 1 of 24
(11,994 Views)

With the "number to read" input set to -1 (the default), Read Multiple is a flush.

FlushStreamImage2.png

> I can't even do a read multiple (get an error code 1059) when I try and create

> that function while having a read or write (single) stream.

I have no explanation for the 1059 error. What data type are you putting through your Stream?

0 Kudos
Message 2 of 24
(10,834 Views)

As I stated before I'm learning this. I am using the high speed stream. The 1059 error happens when I try to create a multiple read on a high speed stream - just found that out. If I try to use a write/read multiple stream, my computer cannot keep up with the write to stream loop when my sample rate is 500kHz, so this is not an option. And there is nothing to the loop. (I don't remember how to do a snipit, so this is a png of that loop.)

Capture.PNG

0 Kudos
Message 3 of 24
(10,834 Views)

Ok, better selection of the number of samples to read at a time, has allowed me to use the read/write multiple. So now all I have to do is rewrite my code to take advantage of this version.

0 Kudos
Message 4 of 24
(10,834 Views)

Skydyvr wrote:

As I stated before I'm learning this. I am using the high speed stream.

Ah. I missed that. My apologies. Rather critical pair of words!

You're correct that I did not include the Read Multiple on the High Speed Stream. I created HS Stream only for those times when Stream wasn't enough, which isn't most applications. In those limited situations that needed very high speed streaming, I did not see any value in the read multiple -- the construction of the array is generally slower than just processing the array through. Also, it substantially complicates the channel to handle Read Multiple when the element type is an array (because of the need to wrap each element in a cluster) -- lacking any use case to encourage its use, I didn't bother implementing it. It seemed like a lot of code for a mostly dead use case.

> The 1059 error happens when I try to create a multiple read on a high speed stream

How do you actually attempt that? When you right click on a High Speed Stream terminal and do Create Reader, there is no "Read Multiple" in the list. What sequence of steps are you trying to even allow that to happen?

> (I don't remember how to do a snipit, so this is a png of that loop.)

Select the code you want, then do "Edit >> Create VI Snippet From Selection"

0 Kudos
Message 5 of 24
(10,827 Views)

> The 1059 error happens when I try to create a multiple read on a high speed stream

>> How do you actually attempt that? When you right click on a High Speed Stream terminal and do Create Reader, there is no "Read Multiple" in the list. What sequence of steps are you trying to even allow that to happen?

I'm good at breaking stuff and comming up with sequences that people dosn't think of . So here is the steps I did: I was trying to replace all the high speed streams with multiple read/writes. I chose to start with the reads. Right click on the stream read -> Replace -> Channel Endpoint... -> Select Stream -> Select Read Multiple -> click ok.I get this error:

Capture.PNG

It works as I would expect if you use intergers (like you posted above), but errors out if using waveforms. Let's see if the snippet works:

Snipit.png

It worked!

You do to reader first, you get the error. You do the write first, no error.

0 Kudos
Message 6 of 24
(10,827 Views)

The error is correct but unhelpful.

Read Multiple isn't supported if the element type is array.

Your original channel is HS Stream of type "array of waveform". If you try to replace the reader first, it tries to make a channel whose element type is "array of waveform", which means it doesn't have a "Read Multiple" node.

If you replace the writer first with "Write Multiple", that creates a channel of type "waveform", and that does have a Read Multiple, so replacing the reader next works fine.

0 Kudos
Message 7 of 24
(10,827 Views)

I am going to adjust the error message to this. Does this text make sense?

Untitled.png

0 Kudos
Message 8 of 24
(10,827 Views)

That looks fine to me. Basically, we don't have arrays of arrays in LabVIEW. Read/Write Multiple use array of element so that won't work if element is an array-- there's just no way to create the type descriptor for such a beast.

Message 9 of 24
(10,827 Views)

That wording looks good, but consider also adding a 'hint' text to that dialog.  Not sure of what exact wording is correct (for example, is the word "always" appropriate?), but something like:

     Hint: Always Create/Modify Write endpoints BEFORE their corresponding Read endpoint(s).


~Tim
0 Kudos
Message 10 of 24
(10,827 Views)