Implementing a Logging Application in LabVIEW With Variable Sampling Rate

Updated May 8, 2024

Environment

Software

  • LabVIEW Professional
  • LabVIEW Full

This article will help users to have an idea on how to implement a logging loop with a certain amount of samples per certain amount of time. 

After following the steps listed in this document, you should be able to develop an application capable of logging data to a .csv file and adjust the required sample rate of this data and the amount of time that it is going to take each logging file (.csv). 

1. First, we want to focus on the parameters that we are going to define and the type of structures that we are going to use in this example. There are multiple ways to define in the block diagram the quantity of time that it is going to take to get each point of data and place it on a log file, but for this example in particular we are going to define this using a For loop nested in a While loop as you can see in the following:
So, for each iteration of While loop we are going to create a new log file (.csv). Then, the internal For loop 'N' terminal defines the number of data points that are going to be taken per log file. Last, the Wait (ms) will define the duration of each data point in addition to the log file. In the example attached to the document, there are 4 iterations with a 15 second duration of the For loop. This means that we are going to create a log file with 4 data points each 1 minute. Users may modify these parameters at their convenience and increase/decrease the time out. 

2. Now, we want to focus on building a path to include the log files that are going to be created. For this, the time and date are usually nice identifiers in order to work or find some specific data points browsing for a certain date and time on Windows Explorer or similar. The proposed approach is the following:

 
This is the common way to create the path. In this part of the code we are defining the name of the log file and including where to allocate the file in memory with the path reference. 

3. Now, we want to include the File I/O functions and include the data points to the log file. In this example, we are using the iteration indicator 'i' as the source of the data as you can see in the following picture:
 
 

 

The data source could be for sure other types of data like strings, doubles, characters, among others. This part will be up to the developer of the application in order to create the required data management. Remember always to close the file reference to make sure that the computer's resources are managed correctly. 

4. At this point, the only thing that we are missing is to provide an initial value in this particular case to the array of the example. you can change the behavior of the logging function if you insert the initial value inside the While loop. Here is a picture of the initial value approach:


                                  


Now we should have all the stages completed. So, the only thing missing is to test the VI. Here is a complete picture of the block diagram of the example:


Note: Notice that the code can't be stopped meanwhile the for loop is being executed, so you need to wait until it completes all the iterations in order to stop the application. 

Attachments