From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading a Binary File - Access Error

Solved!
Go to solution

I'm new to the NI discussion board and had a basic question about using Labview to read a binary file.

 

For my application I need Labview to gather a single value (pulse width) from a custom program that is written in C++. Currently this value is stored in a temporary binary data file. I will be running Labview and the custom program simultaneously.

 

Is it possible to read a binary file using Labview while the file is being written to by another program? Right now I'm getting an access error. I'm using a basic Read Binary code from the Labview example library.

 

Thanks for any suggestions!

0 Kudos
Message 1 of 8
(2,659 Views)

You won't be able to if the other program is putting a lock on the file while it has it open.  Which it what it sounds like it is doing by the error you are getting.  The other program will have to close the file before your LabVIEW program will be able to open it.

0 Kudos
Message 2 of 8
(2,656 Views)

 


@Ravens Fan wrote:

You won't be able to if the other program is putting a lock on the file while it has it open.  Which it what it sounds like it is doing by the error you are getting.  The other program will have to close the file before your LabVIEW program will be able to open it.


I dont think it would be easy for the other application to close the file as I would have to time it with whenever Labview wants to acces it. Although labview has an access error, I am able to make a copy of the file in windows explorer then have labview read that copy. Is there a way to have Labview perform this action autonomously every time it wants to access the data?

 

 

If there aren't any workarounds for this within Labview, I can speak to the programmer who wrote the other application about storing the data in a different manner. Can you recommend any methods for a C++ program to share data with Labview while both applications are running? I was looking at this document, but I am not familiar with C++ and what it is capable of.

0 Kudos
Message 3 of 8
(2,641 Views)

LittleOwl,

 

I dont know of any way to programatically copy a program which is currently in use by another program, and having dual access of the file is prohibited. 

 

What all is the C++ program doing? You may be able simply integrate the functionality into labview. 

 

Regards,

 

Kyle Mozdzyn

Applications Engineering

National Instruments

Regards,

Kyle M.
Applications Engineering
National Instruments
0 Kudos
Message 4 of 8
(2,633 Views)
Solution
Accepted by topic author LittleOwl

I'm surprised that Windows would let you copy of the file if the other program still has a lock on it.  How are you trying to open your file within LabVIEW now?  Perhaps if you open the file with Read-only accesss, Windows will let you open the file within LabVIEW.

 

Yes, you can copy files in LabVIEW.  There are copy functions under the File I/O palette.  Also, you could use a copy command within the System Exec function.

Message 5 of 8
(2,630 Views)

Kyle & Ravens Fan,

 

The C++ file is running a detection and actuation command that measures different analog signals and also drives an analog output signal.  This software is very customized with a particular piece of hardware and would be difficult to integrate into LabVIEW at this stage.

 

Right now, the data collected from the C++ software is being written into a temporary folder.  I can access this data through a LabVIEW example VI called Read Binary File but only when my C++ program is stopped.  For my application, I need both LabVIEW and C++ to run simultaneously.

 

One way I am trying to solve this is by creating a copy of the binary data folder every ~10 seconds with LabVIEW and then reading the data from the copied folder, so as to not interfere with the original binary file. 

 

Does this seem like a feasible approach to solving this problem?  I haven’t had experience making copies of folders with LabVIEW. 

 

Thanks again for all your help!

0 Kudos
Message 6 of 8
(2,607 Views)

Try it!  If it works, great.  If not, then you'll need to find another solution.  Copying a file so that you can read it doesn't seem like the most elegant solution, but if it works....  I have my doubts that it will work because if you are getting errors on trying to open it for reading, I think you may wind up with an error when you go to try to copy it.

0 Kudos
Message 7 of 8
(2,600 Views)

Ravens Fan,

 

The File I/O copy command workaround solved the issue. Thanks for the help!

0 Kudos
Message 8 of 8
(2,591 Views)