Le Cai,
If you acquire more data than will fit in your buffer, then the buffer acts as a circular buffer, and is filled more than once. You will get an overwrite error (-10846) if you do not read data out of the buffer before it is overwritten with new data.
There are several factors that affect your ability to keep up with the acquisition: the scan rate, the size of the data buffer, and the number of scans to read at a time. If your buffer is too small, or you are not reading data out of it fast enough, then you will get the overwrite error. If your buffer is too big, you may get an out of memory error.
Experiment with different values for scan rate, buffer size and number of scans to read at a time. The best combination will result in lit
tle or no scan backlog. A good rule of thumb to start with is: make your buffer size 2 - 4 times as large as the number of scans to read.
Additionally, performing less processing in the read loop can help avoid the -10846 error. Lots of run-time processing in your read loop will slow the acqusiition down and lead to a buffer overflow. To solve this you can either write your data to a file and perform post-analysis or you can create another thread and hand off the current buffer to analyze to the second thread. Therefore, your acquisition thread can continue to run without being slowed down by the processing you are performing.
Regards,
Justin Britten