Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Overwrite Unread Samples

Solved!
Go to solution

I have to program DAQ engine, which has the following requirements:

 

  • sample rate = 10kS/s
  • buffer size = 200.000 Samples
  • unread samples should be overwritten
  • it has to be possible any time to read ALL available samples, doesn't matter how many samples are currently available...
  • ... if 1 second of data is available, then read the last 10000 samples
  • ... if I don't read a minute long, I want to be able to read the most recent 200.000 samples
  • ... after a read, the buffer has to be empty, so that the next read returns only the new data - which haven't been read yet.

 

As you can think, I played days along with the DAQmx Read Property node. But if I set this:

 DAQmx_ReadPropNode.jpg

Then I have to define an absolute offset, i.e. -200000. Then I can't read until my buffer is full. If I attempt to read before, I get an error -200277. It is fully plausible, but let's say, I wait 20 seconds to fill the buffer...

...once the buffer is full, and attempt to read all available samples (-1 input on the DAQmx Read VI), the buffer will be not empty after read. This setting only means, that there are always 200.000 samples available.

 

I haven't found any example under the esamples, and no solution in the forum.

 

regards

Madottati

 

Message 1 of 8
(4,879 Views)

@Madottati wrote:

I have to program DAQ engine, which has the following requirements:

 

  • sample rate = 10kS/s
  • buffer size = 200.000 Samples
  • ... if 1 second of data is available, then read the last 10000 samples
  • ... if I don't read a minute long, I want to be able to read the most recent 200.000 samples
  • ... after a read, the buffer has to be empty, so that the next read returns only the new data - which haven't been read yet.

If you set your buffer size to 200, then you can't read 10000 samples.  The buffer is overwritten when it gets full.  And when you read everything in the buffer (DAQmx Read with count set to -1), the buffer is empty.

 

I think what you really want is to just leave the buffer size as the default and read everything when you do read.  If you just want the last 200 samples, then use Array Subset to just get the last 200 samples.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 8
(4,867 Views)

I have written 200.000 (twohundred thousand) samples -> to hold 20 seconds of data.

 

I have tried the following scenarios, but none of them matches my requirements (in all cases I want to read all available samples, regardless of the number of available samples):

 

1.) This works only as long as the buffer is not full. This reads always the current number of samples acquired, i.e. 85235 samples, then the buffer will be empty. BUT if attempt to read read data after 20 seconds, I run into an error -200279 = "Attempted to read samples that are no longer available".

DAQmx_StandardStart.png

 

 

2.) This reads always the last recent 200000 samples. But there are two things:

a.) I can't read until at least 200000 smples are acquired.

b.) after reading the buffer is not empty. It is a "moving 200000 samples long window"

DAQmx_RelToMostRecSample.png

 

0 Kudos
Message 3 of 8
(4,863 Views)
Solution
Accepted by topic author Madottati

You can modify those read properites while the task is running.  Something like this should work:

 

AI_With_Overwrite.png

 

You have to add a little extra time to your buffer (I went with 1 second)--if you try to read a sample that has been overwritten you'll get an error.  If the amount of data you want is exactly the same as the buffer size it's almost certain that this will happen.

 

 


@Madottati wrote:

I have written 200.000 (twohundred thousand) samples -> to hold 20 seconds of data.


You probably already know this, but in many countries a period is used to denote a decimal point.  Putting periods/commas in numbers other than to show a decimal can result in confusion on forums such as this.

 

Best Regards,

John Passiak
Message 4 of 8
(4,839 Views)

Oops, I'm guilty of a minor Rube Goldberg in that previous example.

 

MinorRubeGoldBerg.png

 

 

Best Regards,

John Passiak
Message 5 of 8
(4,836 Views)

Hi John,

 

thanks for your reply!

 

If I start the task with those settings according to your screenshot, I will get an error on the DAQmx Read.vi, if I don't call it 20 seconds long = when the buffer is full. In my software it is not determined, when to read. It depends on several events, when the read VI is called.

 

Madottati

0 Kudos
Message 6 of 8
(4,818 Views)

It works for me, are you sure you are running the code exactly as written above?  Allocating a bit of extra buffer space is necessary.

 

 

Best Regards,

John Passiak
0 Kudos
Message 7 of 8
(4,808 Views)

No, I didn't run exactly the same code. But now I did it, and it is really working.

 

John, you are the champion! Thank you very much!

0 Kudos
Message 8 of 8
(4,781 Views)