Showing results for 
Search instead for 
Did you mean: 

record all the data acquired by DAQ

Go to solution

Hi all,


I have a problem when I tried to record all the data acquired by the DAQ card. My DAQ is NI 6259, and the Labview version is 2009.


Basically, what I need do is using multiple channels to get the voltages of different point, then I subtract values of two channel (V+ and V-) to get voltage value between two points. In my vi, the sampling mode is continuous and the rate is 100 KHz, DAQmx reading is inside a while loop, and the numbers of samples per channel is set to be 100. After each loop execution I would get 100 data.  I just used the format into file to write the data into a .txt file. It seems after 1 loop only the last one data is recorded instead of 100.  Previously I averaged the 100 data inside the acquisition loop to get one data, so the writing function is OK but it really slows down the program. So I want to write all the raw data to txt file so later I can process them in Matlab.  Is there any way to achieve this? Thank you very much.


The attached is the my vi for 2 channels voltage measurement and the current source control sub vi. I am new to Labview so the question really bothers me even after I read some similar topics in the forum.




Download All
0 Kudos
Message 1 of 6

Hi HongXiang,


There is a coercion dot on the input to “Format into File” indicating that your input data is being coerced into a different format and information could be lost. In this situation coercing a waveform into a DBL numeric results in only retaining the last value of the waveform. One possible way to write all the values to file with minimal changes to your code would be to incorporate something like in the picture below. Here I break out the array of values and cycle through them in a For loop. There are other options to write your information to a file as well. This method with take about 100 times as long the way you were doing it, since it will write all 100 points and not just the last.



Applications Engineer
National Instruments
Message 2 of 6

Thank you for you reply. I tried that, it actually record more data per pulse than before, but less pulses were  recorded (there should be 8 pulses in 20 seconds time but only 2 were recorded), I think it was because the for loop inside slows down the program execution, and sometimes the error 200279 occurred.  I think it would be better to separate the reading and recording process. Someone suggests me rather than writing to the file inside the loop, accumulate the data from all of the loop iterations to generate one large array containing all of the samples then pass that to Format Into File outside the loop. Do you know how to achieve that? I tried the as below, it seems totally wrong , only two data was written. 

Capture 2.PNG

(The subvi nameed 1 (see attachment) converts the 2D array to 1D ) Thanks.

0 Kudos
Message 3 of 6

Hi Skyswan,


Thank you for the detailed postwith images, helps to visualize.  However, you are converting the array of waveforms to a cluster without needing to.  You can simply use the index array VI to pull out the first two waveforms.  Second of all, why do you need to sample all of the channels if you are only using the first 2 channels.  I reccommend only acquiring the first two channels and then seperate intothe channels using the index arry VI and then subtract the two as you have done before.  You can resize the index array funciton to pull out 2 indexed rows of the 2D array.  Also, if you are only concerned with the Y-Value array of the waveform, you can just select Multiple Channels»Multiple Samples»2D Array, and this will save you the step of converting the waveform to an array.  Finally, the method you have would work, and it would just build a large 2D array of all of your data until you press stop.  however, you could run out of memory if the array gets too large.  I hope this helps.



Academic Product Manager
National Intruments
Message 4 of 6

Thank you very much for your detailed reply. I think there was some misleading in my figure, I only connected two samples instead of 8  just because I wanted to try the simple situation. I have corrected the stupid array conversion thing.Now I used 2D array in DAQ reading, and average the data of each channel per reading, later I just wrote all the data into a spreadsheet. Sadly, the out of memory sometimes occurred. I was thinking if there is any way to only record the pulse section of the data because the duty cycle of my pulse is pretty small.

I also experienced that when I set the numbers per channel  to -1, the DAQ will read about 4 data per channel, maybe that explain when I set numbers per channel  to smaller than 4, error would occur, is that true? Thank you very much.




0 Kudos
Message 5 of 6
Accepted by topic author Skyswan

When you set Number of Samples per Channel to -1, it will read all available values in the buffer.  A good benchmark would be to read around 1/10th of your sample rate.  ie. if you are reading at 100Hz, read 10 samples per channel.



Academic Product Manager
National Intruments
Message 6 of 6