04-04-2022 08:10 AM
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
Solved! Go to Solution.
04-04-2022 08:31 AM
@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.
04-04-2022 09:19 AM - edited 04-04-2022 10:09 AM
@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 :
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
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.
04-04-2022 10:07 AM
Lots of different ways.
This works...
04-11-2022 08:19 PM
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