12-10-2021 02:28 AM
Hello,
I have a problem with my LabView Program. I use it to read data from a sensor and write this to a text file. Everthing works fine.
The program works as a state machine. After the last step the program jumps back to the first step and waits for input to start the next measurement cycle.
My problem is that I want to write something into the textfile or rename it after the measurment (in explorer). But I get the error that the file ist still used by my LabView program.
I have a close textfile function behinde every write data function but the textfile is still in use... I don´t want to copie the file every time to change something or to close my labview program.
Is there something I can do to really close the file?
Solved! Go to Solution.
12-10-2021 03:15 AM
code example needed, (you might have an open somewhere that's being left) or you may have a wiring issue.
12-10-2021 10:20 AM
Unless you post your code we can only guess what you are doing wrong.
My guess is you are not closing your file when you program exits.
12-10-2021 11:41 AM
Unlike most posters to this site, I DO have a working Magic 8-Ball.
I don't need a picture to be absolutely certain that LabVIEW is holding open a reference to the text file. This suggests a few things you have done wrong. In fact I bet kudos that you went and stuck the open file in front of your state machine and passed the reference in on a tunnel. I'll give you my best of many possible solutions.
Use an action engine for the File IO.
Ben's famous Action Engine Nugget is always a good read. http://forums.ni.com/t5/LabVIEW/Community-Nugget-4-08-2007-Action-Engines/m-p/503801
Give it open, read, write and close methods at the mininimum ( optionally, add in erase all, get size, delete etc...)
12-12-2021 09:00 AM
Hey
I have 3 interactions with the textfile within my program. The first time is a Create Textfile step. This isn't really necessary but since I create the filename from a timestamp + sensor number combination it felt right to do this.
This is the second step of my statemachine. The first step is just a while loop that stops if someone push the start button. After that the statemachine starts.
Create Textfile
This is my standard subVI to add a new line of measurement data to the textfile. I call it every time if I want to write new data to the textfile.
WriteData
This is the last time I do something with the textfile. After I got all I needed, I calculate the data and write the results at the top of my file.
Create Header
After this step, the statemachine jumps back into the first step (while loop). If someone press the start button the while loop stops and the statemachine starts again. It creates a new textfile from a timestamp + sensor number, whrite measurement data and the results and than jumps back to the start.
I hope that helps to understand my problem better.
12-12-2021 11:41 AM
Post ALL of your code NOT pictures of code fragments.
Simply attach the entire VI to your post. If it needs a lot of Sub-vi's then Zip them together and attach the zip file.
12-12-2021 11:56 AM
Try wiring a True to the disable buffering input of the O/C/R File functions.
12-13-2021 03:20 AM
@RTSLVU wrote:
Post ALL of your code NOT pictures of code fragments.
Simply attach the entire VI to your post. If it needs a lot of Sub-vi's then Zip them together and attach the zip file.
Did you not read the first post???
12-13-2021 03:30 AM
File Indicator in step 2 (first image) goes the local in create header... (last image)
in neither of these cases are you wiring your error cluster through, so if you have an error on creating the file/opening it you're then going to try and read/write to it at the create header step -hmmm, that may cause issues. (If you have error 8 permissions issue you might have a problem here.)
Path comes from where in the Step for appending data? the file path comes out of the close VI and should be wired out of the message header for use.
I suspect that either Path or File control is empty - unless you're going to define it to us where you've built up the path and this might be causing issues.
(Look at your error handling and file path handling)
James
12-13-2021 05:53 AM
@James_W wrote:
File Indicator in step 2 (first image) goes the local in create header... (last image)
in neither of these cases are you wiring your error cluster through, so if you have an error on creating the file/opening it you're then going to try and read/write to it at the create header step -hmmm, that may cause issues. (If you have error 8 permissions issue you might have a problem here.)
Path comes from where in the Step for appending data? the file path comes out of the close VI and should be wired out of the message header for use.
I suspect that either Path or File control is empty - unless you're going to define it to us where you've built up the path and this might be causing issues.
(Look at your error handling and file path handling)
James
Not really. Close File closes the ref even with error in TRUE and, somehow the ref is not releasing until Windows garbage collection comes around when the top level vi goes idle.
"How can that happen???!" you ask. Well, what if the Windows OS allows for some sneaky ability like holding open a buffer to the file in an application space that has multiple file access? And yes, that is why there is a "Disable Buffering (f)" optional input to the Open Create Replace File function that is ignored on Linux and Mac platforms that don't allow file Buffering.
You are correct that the error chains should be wired but automatic error handling would pop up any error 8.