Example Code

Write Continuously to CSV File with Low Level File I/O Functions Using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Download All

Overview:

This example show how to write CSV files by opening the file and leave it open until finished all of writing before finally closing the file.

 

Description:

We can easily write CSV files by utilizing the 'Write To SpreadSheet File.vi'.  However, this function internally includes both the Open/Create/Replace and Close file functions.  As such, these functions can lead to race conditions when utilizing the 'Write to SpreadSheet File' in a while loop.  This is due to continually telling the operating system to open and close the file.  In this manner, we may have a call to reopen the file when it is still open or perhaps in the process of closing leading to an error.  The following code demonstrates how we can open the file and leave it open until we are finished with all of our writing before finally closing the file.

 

Requirements:

  • LabVIEW 2012(or compatible)

 
Steps to Implement or Execute Code

  1. Run the vi.
  2. Choose the CSV file path.

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

 

Cole R.
National Instruments
Software Engineer

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.