LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

File access problem

Solved!
Go to solution

In a program I am logging Comma-Separated-Values into an ASCII file every 5th second, interval may change from every second to once every hour. How can I set up a system so that it is possible to access/get a copy of this file/information during the test, without destroying the process of adding new lines, if that is happening at the same time I am reading/copying this file from another subroutine. This general problem must have been solved long time ago, I expect.

Martin

0 Kudos
Message 1 of 5
(1,599 Views)

@MartinP wrote:

In a program I am logging Comma-Separated-Values into an ASCII file every 5th second, interval may change from every second to once every hour. How can I set up a system so that it is possible to access/get a copy of this file/information during the test, without destroying the process of adding new lines, if that is happening at the same time I am reading/copying this file from another subroutine. This general problem must have been solved long time ago, I expect.

Martin


Consider the file output an output. The output is generated from internal data. Data that you can keep and use.

 

For instance, send an event with current data. The file loop stores this to disk, the GUI puts it on screen, some other (or the original) loop can buffer the data to keep a history.

 

Reading back from data you generate yourself should probably (and can mostly) be avoided. If you really think you can't avoid it, you might have to make some sort of interlocking.

 

Also, you can read from a file and write from it in a parallel loop. As long as the read only uses read access, this shouldn't conflict with the writes. Of course you run the risk of reading partially written data.

0 Kudos
Message 2 of 5
(1,588 Views)

@MartinP wrote:

In a program I am logging Comma-Separated-Values into an ASCII file every 5th second, interval may change from every second to once every hour. How can I set up a system so that it is possible to access/get a copy of this file/information during the test, without destroying the process of adding new lines, if that is happening at the same time I am reading/copying this file from another subroutine. This general problem must have been solved long time ago, I expect.

Martin


If you use Open/Create/Replace File and pass a reference instead of using one of the easy Vi's like "Write to delimited Spreadsheet" or worse yet the "Write Measurement File" Express VI. The operating system (Windows) takes care of it for you.

 

The problem with the easy way is, every time you write data to the file Windows will :

  1. Open the file
  2. Write the data
  3. Close the file

So if you open that file to read it in between writing intervals and still have it open the next time your program tries to write to it, your program will receive a File Sharing Violation error because the file is open by another program.

 

If you use Open/Create/Replace File and pass the File Reference it works this way 

  1. Open the file at the beginning of your program
  2. Write data to the file as needed in your program, passing the same file reference around your loop using a shift register
  3. Close the file at the end of your program 

Now if you try to open the file in between writing intervals you will receive the File Sharing Violation error in the program that just tried to open the file because your LabVIEW program still has it open. Windows should give you the option to either open the file in Read Only mode or open a copy of the file.

 

I just reread your post and I think you are trying to read and write the same file with the same program? I have to say I have never tried that but I believe you will run into the same file sharing issue. Instead of writing the file and then reading the same file later, (I am guessing for charting or analysis?) why not write the data to your file at regular intervals and just keep the data in an array for charting or analysis? Or just make a copy of the file and open the copy.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 5
(1,566 Views)

Lots of different ways.

This works...

 

Frozen_0-1649084789044.png

 

 

---------------------------------------------
Former Certified LabVIEW Developer (CLD)
0 Kudos
Message 4 of 5
(1,551 Views)
Solution
Accepted by MartinP

Thanks for all your thoughts and ideas. Considering the size of the file I get after some days of testing etc, I believe the

best option for me is to use a Pause-Logging button while I copy the file.

Martin

0 Kudos
Message 5 of 5
(1,491 Views)