LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to write to file at user defined interval

Solved!
Go to solution

Hello

I am trying to find a way to take data samples from a stream of strain measurements that is input to Labview from a NI 9237. These samples must be written to a file for later analysis. The vi must be capable of recording a burst of data at a user defined interval and sampling rate.

For example record at 10Hz for 10 seconds every 15 minutes.

My attempt at doing this is attached (as you can probably tell see I am quite a beginner at Labview).

20419i7565B3982CA0F596

In my example I have used a random generator to simulate my data from the NI 9237. By using a for loop I have tried to get the vi to write 5 data points to the file. However it writes the same data point to the file 5 times, instead of 5 successive data points.

Ultimately I would like the vi to write data to the file for a period of time (10 seconds) instead of writing a defined number of data points.

Can anyone please advise how I should go about achieving this?

Many thanks

0 Kudos
Message 1 of 9
(4,976 Views)

I tried to show in an example what I mean. You can you Notifier operation or Queue elements to trigger the savin loop. It is up to you!

 

0 Kudos
Message 2 of 9
(4,969 Views)

Here is how I would do it.

 

20425i36851C9E9526B9DC

Tim
GHSP
0 Kudos
Message 3 of 9
(4,960 Views)

Many thanks for the suggestions. I'll give them a try.

Regards

0 Kudos
Message 4 of 9
(4,941 Views)

Hi,

The reason you get the same value every time is because the random number generator lies outside the for-loop, it will generate a new value every time the while-loop runs another iteration, not the for-loop (so now it will generate a number every 15 minutes).

 

In this case there is no need to use sequence strucutres (as the previous posts already have showed), but if you use sequence structures you can add another frame to it instead of having two different structures.

 

Also, is there any particular reason that you don't want to write a specific amount of data points? If you sample uniformly it is easy to calculate how long a certain number of samples will take and if you sample uniformly in the same rate for a specific period of time you will always get the same number of datapoints. 100 samples at 10 Hz will take 10 seconds to acquire. Since you are a beginner in LabView I would recommend that you take a look at Getting Started with NI-DAQmx to get some tips on how you can acquire your data.

 

Regards

Anders

0 Kudos
Message 5 of 9
(4,917 Views)
Hi Tim It has been a long time since I last worked on this project, but now I am back. Unfortunately I am struggling with the same problem as before. I have tried your solution and found that it delays the write to file action by the time specified in ‘time interval’. It then writes data to the file and continues writing indefinitely. This is a good start for what I’m trying to achieve, however it is not the complete solution. After the initial wait I need the VI to record (write) data for a specified time (eg 10 seconds) and then stop writing data. After this it must wait 15 minutes, before writing another 10 second burst of data to the file. This is to be repeated until the VI is stopped by the user hitting the stop button. Basically, the test rig where this VI will be used produces a lot of data and it is not necessary to record all the data. So I’d like to capture short bursts (10 seconds) of data every 15 minutes. Do you have any further suggestions? Regards Kevin
0 Kudos
Message 6 of 9
(4,744 Views)
Solution
Accepted by topic author tone5
Message 7 of 9
(4,723 Views)

I would create a separate task which is used to write the data. Data to be written to the file can be passed to this task via a queue. You could set values to determine how much data needs to be written and at what intervals. Your data acquisition can post data to the queue. Your queue can be configured so that it will only contain enough entries to hold the amount of burst data you want to save. Any additional data posted to the queue would be dropped. Your write task could be in a loop that periodically checks to see if your time interval has been met. When it does it can dequeue all the elements from the queue and write them to the file. It will go back to waiting for the timer to expire. Now that the queue is empty your data acquisition will be able to fill it again with the next set of data.

 

NOTE: When you have your logger task pull the data from the queue you should use the queue status vi to grab all of the data at once and then flush it. If you dequeue elements one at a time in a loop your data acquisition task will start filling it again before you have written everything out. This would result in more data getting written to file than you want.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 8 of 9
(4,721 Views)
Many thanks J-M. I think this will work for me.
0 Kudos
Message 9 of 9
(4,689 Views)