Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Efficient Logging?

I am acquiring quite a lot of data in real time acquisition from my ni dac
board using Meas.Studio 6 for visual basic.
I want to log it to disk (in an ascii text file). If I open,print#,close
after each data point it is SLOW!
Instead, I want to build a buffer and occasionally flush it to disk.
1. What is the optimum text buffersize to flush (for speed)
2. would it be efficient to
open file
do
acquiredata
print #
until (finishedacquireingdata)
close #

3. Is the Print#, or TextStream faster??

4. Any other suggestions?

TIA
Steve
0 Kudos
Message 1 of 2
(3,241 Views)
Are your concerns about your current method of logging being too slow related to the rate of acquisition you are able to achieve? The method you described sounds as though you are doing single point acquisition in a loop and with each update logging that single point to a file. Here are some alternatives to speed the process a little:

1) Perform double-buffered continuous acquisition so that your daq board performs its acquisition task asynchronously in the background of any logging task you desire to do with the data acquired. Look at the example in your ...\MeasurementStudio\VB\samples\DAQ\Analog Input\Continuous Acquisition directory to get an idea of how to perform continuous acquisition. You should pay special attention to the CWAI1_AcquiredData event handler subroutine because this is where you would place your code to log the acquired data to a file. Note that this subroutine is executed as acquisition continues to run in the background on your daq board, so there can be no real complaint about this slowing down your acquisition speed at all.

2) Other than the above solution you could do single point acquisition in a loop and write the data points to consecutive indices in an array. Once the array is filled with enough points you could then write it to a file in the manner you proposed, but acquisition would have to stop in order to do so because processes in VB are executed synchronously. The only real alternative you have to do this asynchronously would be to make a multithreaded app that spawned a new thread once the array hit a certain fill level, and in this new thread wrote the data to a file with the process being continually repeated in a loop: (1)fill array, (2)spawn thread, (3)continue acquisition in main thread, (4)write data to file in second thread. The drawback to this idea is that VB does not natively support multithreaded programming and will crash if you try to debug a multithreaded app in its environment. Also this method is just simulating the first solution I proposed (see #1), but in a less efficient and slower manner, not to mention the multitude of complexities it introduces.

As far as Print# or TextStreams being faster, I don't know, you will have to set up a timing schema to sort that out for yourself. One thing I can tell you though is that you do not have to keep opening and closing the file continually in your app, in fact you might not want to do that at all for the simple fact that it will reset your file pointer everytime you go to write (unless you open only for appending).

Jason F.
Applications Engineer
National Instruments
www.ni.com/ask
0 Kudos
Message 2 of 2
(3,241 Views)