Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

daqmx buffer read

I have a theory question on the read and write of the daqmx to the buffer. 

 

For example, if I were to do an analog in continuous acquisition with 50Hz (50 samples per second), and I am reading 49 samples per second, would my buffer overflow, since I am adding one extra sample in the buffer every second. 

 

Instead, if I were to read 51 samples per second, would I eventually be reading samples that are not there, since I am reading one sample faster than I sample? 

 

I understand that it could be possible that the buffer size would adjust itself in the first case (if so, how do I ensure that?), but eventually, the buffer size will go out of control, wouldn't it? 

 

I am working on an application that require me to sample continuously, and it seems to me that if I don't set up my sampling adaptively, my program would crash eventually.  Let me know if you can help.  Thanks!

 

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 1 of 3
(3,046 Views)

If you aren't keeping up with reading your newly acquired samples, yes, you will eventually overflow (your task will error and end).  Depending on how you configure your task, it could take a really, really long time with the numbers you've provided.  You could also set your task to overwrite unread samples and then you would not overflow.

 

For your second question, the short answer is you can't.  You can't read faster than you are acquiring.  The read call blocks until the number of samples requested is acquired.  So if you generate 50 samples / s and request 51 samples, it will take (roughly) 1.02 seconds to return.

 

For a continuous task, the key is to keep up.  You can request -1 samples to tell the read call to return all available samples.  Call read continuously and process later.  Otherwise you need to call read often enough to keep up with your acquisition.  There are all sorts of games you can play with adjusting your buffer size and read sizes but it really depends on your application.  If you post some more details I might be able to help you more.

0 Kudos
Message 2 of 3
(3,044 Views)

I have tried the options such as reading all available samples and setting buffer overwrite to true, but they returned buffer error (shouldn't these option prevent me from getting an error??).  I guess that is how I got the misconception that when there is not enough samples in the buffer while I am doing a read, and error could error.  However, from what you said, it seems like the read operation would wait until adequate number of samples are available before attempting to read, so I really don't understand. 

 

I would post some code up, but I don't know where to begin, since there are a few routines that are coupled together.  However, let me try to describe what I am trying to do.

 

I have a measure.vi function global that has two functions: initialize and measure.  When initialize is called, virtual channels are created and acquasitions are started.  After initialization is called, measure can be called regularly to read buffer. 

 

Mainly, I am trying to read a 0 to 5V pot feedback voltage that indicates the position of a motor.  The program would energize the motor, use measure to get the feedback voltage, check the feedback voltage with a given criteria, and either continue to energize the motor or stop the motor if the criteria is satisfied.  My progarm is working smoothly when the motor is energized with a pure dc (one smooth continuously motion) until a particular position is hit, but when I drive it in pulse (20ms high and 160 low) until a particular position is hit, it seems like the the feedback read from my program doesn't change.  The analog module for my compact dax and the feedback signals seem to work fine; I used MAX and DMM to check , but my software is not working properly.  Any suggestion would help.  Thanks!

 

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 3 of 3
(3,028 Views)