LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write data to file every 10 (or N) loops

I am acquiring voltage data continuously. My loop reads 1000 samples, averages those samples, writes the result to a measurement file (appending the data to previous data), and repeats.

 

I want to change my VI so that every 10 loops I write 10 data points (from the 10 previous loops) to a data file. This way I am writing my data less often and my loop will run faster.

 

I have found a way to write my data every 10 loops, but this method only writes the data from the current loop (not from the previous 10 loops).
https://forums.ni.com/t5/LabVIEW/write-to-measurement-file-at-every-n-iterations/m-p/3158860#M910863
https://sine.ni.com/srm/app/newrequest#


How can I modify this method to include the data from the previous 10 loops?

0 Kudos
Message 1 of 8
(7,805 Views)
You just want to write the previous 10 averages? You could simply append each one into an array that is maintained in a shift register. After writing, empty the array.
0 Kudos
Message 2 of 8
(7,785 Views)

Write to csv every 10 lines.png

 

you can do something like this.

Munna
Message 3 of 8
(7,750 Views)

Hi Solobo,

 

This might be what you look for.

 

write10data.png

 

Nate

Message 4 of 8
(7,699 Views)

What format are you saving the data?  How are you acquiring the data?  Can you share what code you have so far?

 

There are likely ways to make your code a lot more efficient without needing to do the writing every 10 loops.  Two that immediately come to mind:

1. Make sure you open the file before your loop and close it after your loop.  This will save you a ton of time over open, write, close each time you want to write to the file.

2. Use a Producer/Consumer architecture so that your writing to file and acquiring of data are done in parallel.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 8
(7,627 Views)

Dennis_Knutson: Yes, that's my goal. I think I understand what you're saying in principle,  and that seems like the simplest solution. I'm a little fuzzy on how to clear the array and start gathering again.

 

Munna232: Is your example just increasing the size of the array indefinitely and writing it once when its size is 10? Or is there something I'm missing that clears the array and starts over after writing 10 samples?

 

NateMan3148: I think I see how your example would work, but I need to think about whether it would hinder or help the speed issue I'm having (every once in a while my save operations freeze up for a bit and my buffer fills up before I can gather more data to clear it).

 

crossrulz: I'm saving as a .csv and acquiring data continuously @ 1kHz. I'll share a screenshot of the code below.

Re 1: If I open the file before my loop and close it after, then do I lose data if something causes the computer to freeze up? The reason I'm writing data often is as a "back up" so I don't loose my data if the loop is not allowed to finish for some reason.

Re 2: I haven't heard of Producer/Consumer architecture, but looking at your link it looks promising: if I'm understanding it correctly, I would acquire data outside of both loops. My first loop would then do calculations on the data and append processed data to "buffer" of sorts using a shift register. My second loop would then look at that "buffer" and acquire / save data from it at its leisure. Is that the gist?

 

Screenshot of my current code (writes only every 10th data point):
WritesONLY1DATAPOINTEvery10Loops.png

 

 

 

 

0 Kudos
Message 6 of 8
(7,593 Views)

solobo wrote:  Re 2: I haven't heard of Producer/Consumer architecture, but looking at your link it looks promising: if I'm understanding it correctly, I would acquire data outside of both loops. My first loop would then do calculations on the data and append processed data to "buffer" of sorts using a shift register. My second loop would then look at that "buffer" and acquire / save data from it at its leisure. Is that the gist?

No.  You would have one loop do the acquisition as you have it now.  You could have it do the mean and the other calculations as well.  But then the second loop logs the data.

 

Also, you could combine both of your two FOR loops into a single loop.  You could also Autoindex your Rp Val and Offset arrays instead of using the Index Array.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 8
(7,584 Views)

I know its a very late reply but I have the following way of writing a specified set of data points to a file with continuously running loops.

I am doing it so that I can aquire data at 1000Hz but only save at 100Hz etc.

My appoligies if my explanation is slightly off im not the greatest programmer.

 

You need to use Producer consumer loop architecture and que the data to be saved.

vi's used;

Insert into array - Builds array from unqueued data

Transpose 2D array - Transposes (to enable columns now rows to be counted)

Index Array - Seperates top row (one value from every column)

Array Size - Shows how many values in top row (i.e how many columns)

Delete from array - Clears array

 Save every N samples.png

 

 

0 Kudos
Message 8 of 8
(6,157 Views)