LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

write data to file periodically

Hi,
I work on a labview project. I need to record data from compact field point every 100ms and calculate 15min average value of the input data, then save the average value into file continuously. I have already done the data record part. My problem here is when labview save the result to file, I can not record the input data at the same time for the next 15 minute average calculation. I will miss some input data from CFP while saving data to file. How can I keep these data for the next 15 minute average calculation while I am saving the result into file. Thanks for your help.
Fred
0 Kudos
Message 1 of 6
(3,799 Views)
If I understand you correctly, the act of writing the file is disturbing your timing on the data-collection part.

You need to have an average of the latest 9000 samples (15 * 60 * 10), and write the new average every 100 mSec.

Are you opening/writing/closing the file each time? While that's the safest way (file is intact even if LabVIEW or your program crashes), it's not the fastest.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 6
(3,799 Views)
Hi,
Thanks for your response. According to my designd program, I have already done the part of the latest 9000 samples, and I did open/writing/closing the file each time, and it did disturb my timing on the data-collection part. Therefore, is there any method or solution to overcome this issue? Thanks for your help.
0 Kudos
Message 3 of 6
(3,799 Views)
Are you reading the 15 minute data file and computing mean? how about, writing the data to file as you are but adding the running sum of each value and dividing by N at the end of the sample period. This will eliminate the file read/compute accumulate the running sum as a double so that you don't run out of headroom. (or divide by N before adding to the running sum).
Stu
0 Kudos
Message 4 of 6
(3,799 Views)
The easiest way is to open (create) the file once at the beginning of the acquisition, and leave it open. You should use DENY WRITE permissions, at least, to prevent other apps from writing the file.

Start with an empty array of data in a shift reg.

Repeat
Get new value

Use BUILD ARRAY to prepend the new value to the existing array (IN FRONT OF the old data).

Use ARRAY SUBSET to limit the array to 9000 samples.

Use SUM ARRAY ELEMENTS to figure the sum.

Use ARRAY LENGTH to find out how many you have.

Divide the sum by the number N, and that's your current average.

Write this directly to the file, or convert it to ASCII and write that.

until done.

Close file.

This maintains the ave
rage, even when you have less than 9000 samples in your buffer.

The DISADVANTAGE of this, is that the file is open during the whole event. You'll have to take special care if you want some other program to open the file while data is coming in.

That also means that the contents of the file ON DISK are not necessarily up to date - there could be a block of data in memory that's not been written to disk yet. (Because of the OS, not because of your code).
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 5 of 6
(3,799 Views)
Hi,
Thanks for your response. I am really appreciate your help. I will try your suggestion for my application. Thanks again.
0 Kudos
Message 6 of 6
(3,799 Views)