LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't close textfile after whrite data

Solved!
Go to solution

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?

 

 

0 Kudos
Message 1 of 16
(4,133 Views)

code example needed, (you might have an open somewhere that's being left) or you may have a wiring issue.

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 2 of 16
(4,126 Views)

 

 

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.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 16
(4,085 Views)

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...)


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 16
(4,079 Views)

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.

Dateierstellung.jpg

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.

MessVI.jpg

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.

Auswertung.jpg

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.

 

 

 

 

0 Kudos
Message 5 of 16
(4,050 Views)

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.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 6 of 16
(4,041 Views)
Solution
Accepted by JÞB

Try wiring a True to the disable buffering input of the O/C/R File functions. 


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 16
(4,036 Views)

@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???

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 8 of 16
(4,017 Views)

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

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 9 of 16
(4,013 Views)
Solution
Accepted by JÞB

@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.


"Should be" isn't "Is" -Jay
0 Kudos
Message 10 of 16
(4,006 Views)