From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Handle File Already Open Error using Queues in 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

Overview

This example handles the "Error 5 - File already open” generated when opening an already opened file

 

Description

Sometimes you may have are multiple programs accessing the same data file.  If LabVIEW tries opening a file that is another program already has control of (such as data backup software), you will get error 5 when trying to open the file in LabVIEW. This can cause problems if you are logging data and need all of it to be written to the file. This problem can be avoided if you use queues to write the data, and handle this specific error.

 

Requirements

LabVIEW Full Development System 2012 or compatible


Steps to Implement or Execute Code

  1. Choose the appropriate file in the file path control.
  2. Run the VI
  3. Simulate the error using the Fake Error button, When error 5 is encountered, the data will be added to the queue so no data is lost.

 

Additional Information or References

VI Block Diagram

 7212.PNG

 

**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.

Comments
majkl21
Member
Member
on

"Close file reference" should be inside "No error" case structure, else error code 5 generates error code 1 after passing thru "Close file reference" (because input file reference is invalid).