LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Save Report to File.vi closing file problems

I have a while loop running in which I generate data. At the end of a sequence in the while loop, I create an HTML report and save the report file to disk. My problem is that the next time the while loop generates data and goes to save the new HTML report, I get a file permission error (Error 😎 in the delete file subvi. I use the delete file subvi so that I can programmatically replace the HTML report file. I believe that the problem is in the "Save Report to File.vi" in that it does not close the file after it writes it. Any comments?
0 Kudos
Message 1 of 7
(3,959 Views)
Please post your code, or a GIF image thereof (smaller file, so those of us with cheesy dialup connections can better view the image).

It sounds like you may be overlooking something quite easy, but without seeing the code, I can't ascertain for certain.
0 Kudos
Message 2 of 7
(3,959 Views)
Pictures help.

Just guessing now.
How quickly after saving the file do you attempt to delete it?

Doing a save and soon after attempting a delete could cause problemsue to delays in the file I/O processing.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 7
(3,959 Views)
Here is my code. I've included 2 second waits, so timing does not appear to be an issue.
0 Kudos
Message 4 of 7
(3,959 Views)
I had an identical problem and found that it was due to the "save Report" VI. If you check its diagram you can see that the file is opened but never closed. I solved the problem simply adding a "file close" just after the "write to file" on the right of the diagram. I think this can be considered a bug in a Labview VI. How can i report it ?
0 Kudos
Message 5 of 7
(3,959 Views)
Unfortunately i couldn't open your example as i only have LV 6.0, but i looked at the 'Save report to File.vi' in LV 6.0 and it basically only contains a 'Write characters to file.vi' for file handling. In LV 6.0 this vi does contain a 'Close file+.vi' which has an input called 'close when? (now:T)'. Make sure this is wired as True (default) and the file will close, and you should be able to delete the file (as long as the delete event occurs afterwards (make sure it is wired in sequence). In the LV help, it says the reason for the 'Write characters to file.vi' only closing if you tell it to (set as default) or if there is an error is so you can continually use it in a loop, writing characters to file, without closing, and then send a command to close
it only on the last loop, or if there is an error. Therefore i dont think it is a bug, but i think there should be a wire for it on the 'Write characters to file.vi'.

I hope this helps you..

Kim
0 Kudos
Message 6 of 7
(3,959 Views)
Your instincts are right on the money. If you open Save Report to File.vi you will notice in the HTML case in the far right that a reference to the file is opened but not closed. I inserted a close after the write file function and before Generate Report Set Modified Data.vi and it worked like a champ.

Jeremy
0 Kudos
Message 7 of 7
(3,959 Views)