LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

saving data from graph to file

Hi all,

 

i need litle help regarding saving signal from graph to file.  

I manage to do something, but i get several columns in my txt file.

I would like to have one with time, and one with values, but i can't do it.

Please check att.

 

Thank you for your help

Download All
0 Kudos
Message 1 of 5
(2,067 Views)

Hi milan,

 

but i get several columns in my txt file.

Because you have it programmed this way!

In the inner FOR loop you create two rows: one for time information, one for Y values. Those two rows are then appended to the data in the shift register. In the end you will have a 2D array with lots of rows in the shift register…

 

Suggestion1:

Use 2 shift registers, each keeping a 1D array. Use one array to hold time data, the other to hold Y data.

With each iteration of the while loop you concatenate new data to each of those arrays.

After the while loop you build a 2D array from both 1D arrays…

 

Suggestion2:

Use AppendWaveforms to build a large waveform from your DAQ data. Convert that waveform after the while loop…

 

There are other options as well…

 

On your VI:

Why don't you (auto)cleanup?

Why do you use FromDDT instead of IndexArray?

Why do you use DAQmxRead in "n chan" mode when you only include one channel in the DAQmx task?

Why don't you use the DAQmx feature of saving DAQ data directly to a TDMS file?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(2,055 Views)

I think that GerdW is awake before I am -- I seem to "add more information" to his posts.  So I'll just make a few comments.

  • I like your DAQ Code -- you use DAQ functions, collect data as an Array of Waveforms (which includes the timing data in an abbreviated form, t0, the timestamp of the first sample, and dt, the time difference between the samples).
  • You set the Sample Mode to "Finite Samples".  This probably means that if you take 1000 samples/second, when the DAQ Read finishes, then all the remaining code in the While Loop has to run before you get around to doing the next DAQ Read, which means the second set of 1000 samples won't start until some time elapses after the previous DAQ Read ended -- there will be a gap when no data are acquired!  You probably don't want that!
  • The solution to the previous problem is to make the Sampling Mode to Continuous, which starts the next sampling for the next DAQ Read just when the last sample for the current DAQ Read has been acquired (and the DAQ Read finishes).  If you are sampling at 10kHz and are acquiring 1000 samples, this means you have 1000/10k = 0.1 sec to finish all the rest of the code in the Loop and get back to the DAQ Read in the next loop to allow acquiring Data without "gaps".
  • Should your processing take longer than 100 msec (you are doing a Graph update, accumulating data in arrays for writing to a spreadsheet, etc.), you will still have "data gaps".  However, you can greatly reduce or (in most cases) eliminate the gaps by using a Producer/Consumer Design Pattern, where your Producer Loop consists of the DAQ Read and then placing the data in a Queue (or Stream Channel) and sending it to a parallel Consumer Loop which plots, formats, analyzes, etc. the data, running in parallel with the Acquisition loop (which takes almost no CPU time, letting the Consumer run at full speed).
  • Now your output.  Since you are using a Waveform, if you do use Continuous Samples and thus don't have "gaps" in your data, it becomes "wasteful" (and unnecessary) to write all three, or even one, Time Channel since you can compute all of the Times from t0 and deltat (the time of Sample k will be t0 + k*dt).
  • Note also that you are writing time as "Time of day to the nearest second", yet your samples arrive every 0.0001 seconds.  Thus you've thrown away almost all of the precision of your time data.  You can fix this by using a different Time format.

Bob Schor

0 Kudos
Message 3 of 5
(2,048 Views)

 

 

Hello,

 

thank you a lot for your reply and explanation.

Producer/consumer architecture looks as very good, but this is totaly new for me (and generaly labview), so i am stuck now with adjusting X, Y scale. 

I implemented one graph in first while loop to see ho sampling is working.

Problem is in second loop, because i get nothing on graph.

Also in att.

 

Thanks.

1.JPG

0 Kudos
Message 4 of 5
(2,017 Views)

Hi milan,

 

Problem is in second loop, because i get nothing on graph.

Wrong: you get something in this graph!

(Change the plot style to show points for each sample to see a point in your graph!)

Why do you use a graph instead of the chart? And why did you hide/delete the label of that graph?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 5
(2,006 Views)