To download NI software, including the products shown below, visit ni.com/downloads.
Overview
To Improve the efficiency of using the File functions within the LabVIEW
Description:
All of the functionality of the Write to Spreadsheet VI that is included with LabVIEW are broken down into separate VIs so that the writing can be done efficiently in a loop. The VI included with LabVIEW would open the reference to the file every time the loop is run. With these VIs you can avoid opening and closing the file whilst writing in the loop.
Instructions:
To implement this example:
To execute this example:
Requirements
Software
LabVIEW 2012 or compatible
Hardware
-
**This document has been updated to meet the current required format for the NI Code Exchange.**
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
Do we still need timing in the loops when using these VI's?
Hi rsw,
You should still use timing with these VIs as writing to file is still quite an intensive process. This method will just free up the processor a little to do other things as well. A good application would be in a producer consumer loop that you want to do some analysis in and then write to file. As it avoids opening the reference on every iteration of the loop it means that there are a lot less reaquests for memory access, which is the thing which makes it so intensive on the processor.
At the end of the day, if you want to run your loop really quickly, try the VIs and see how fast you can go. You can monitor your CPU usage with task manager and see whether it's killing your processor.
Chris
How is the easiest way to use these? Do we just throw these 3 into our loop where the current write to spreadsheet is? Do we need all 3 if we are just trying to write to a spreadsheet while appending all of the data to a single file?
I have a program reading from a device and all I want is to be able to read a data point every x number of minutes and append each point when a new one is taken while being able to walk away from the device. Currently that can't happen since it asks where to save it each time through the loop.
Hi Dan,
If the file name will not change during the saving then you can place the
'Open' VI outside the loop and the 'Close' VI outside the loop. If you
need to be able to create new files with different names during the
operation then you should use an architecture similar to the one outlined
in the second picture. This will check to see if a) a file has already
been created and b) if the name of the file has changed. If the file name
is changed then the 'Open' function is called again and a new file is
generated.
You should look at using shift registers and the 'First Call?' function in
LabVIEW. The 'First Call?' function identifies whether this piece of code
has been run before and is useful when initialising code.
Does this help?
Regards,
Chris