LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to close a CSV file if it is already opened.

I am writing a program which inputs data from the VI into the CSV file. I want to make sure the CSV file is closed at the start. Is there a way in order to do so. Can anyone give me an example?

0 Kudos
Message 1 of 39
(4,308 Views)

Technically, only the process context that opened the file can close it. Closing a file not only marks it as closed but writes any residual data waiting to be written to the disk. After that the mapping to memory is invalidated, the memory used for the files is unmapped and made available and then the files is marked as closed.

 

Just jumping in a closing a file from another process is just asking for trouble.

 

Now tell us why you asked this question and what is it about the process that is writing to file that prevents it from closing?

 

Ben 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 39
(4,295 Views)

I have written a program which gets data from a CSV file. This CSV file is getting data from a graphical user interface. And one places a battery inside and the GUI reads and fills the CSV file but the info only gets into the CSV file if it is closed. I want to make sure the file is closed at the start in order for data to be written. Either using LABVIEW or TestStand to close this file.

0 Kudos
Message 3 of 39
(4,288 Views)

I am even more confused now.  So a GUI opens/creates a CSV file.  It will hold the reference.  Later, that same GUI is using the data that you wrote to the CSV file?

 

If I understand correctly, there are a couple of things you can do.  The simplest is to just store the data in a shift register, open-write-close when you need to, and then use the data in the shift register when you start the test.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 39
(4,277 Views)

Maybe it's just me, but that seemed a bit strange.

 

The GUI is some application.  It creates the CSV.

Another application reads the CSV.

 

You're having issues with the first application writing to the CSV because it won't write to the file if it's already open.

 

Does that sound right so far?  If so, you've left out a pretty key element.  What has the file open?  Given your description, there's only two places that make sense for this to be open.  It's either open in the GUI application or the reading application.  Instead of trying to do something in a strange way, why not take a look at these two applications to see if you can close the file correctly?

0 Kudos
Message 5 of 39
(4,268 Views)

I guess it's time to show the code you have.  It seems too complicated to explain a few sentences.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 39
(4,267 Views)

@crossrulz wrote:

I am even more confused now.


Guess it wasn't just me

0 Kudos
Message 7 of 39
(4,263 Views)

Kind of. The GUI opens/creates the file and stores the information. But the GUI will only append to the file if the CSV file is closed. I cannot have the CSV file opened and have it input data to the file. So I want to make sure the CSV file is closed right at the start of the program.

0 Kudos
Message 8 of 39
(4,261 Views)

@sportsguy99 wrote:

I have written a program which gets data from a CSV file. This CSV file is getting data from a graphical user interface. And one places a battery inside and the GUI reads and fills the CSV file but the info only gets into the CSV file if it is closed. I want to make sure the file is closed at the start in order for data to be written. Either using LABVIEW or TestStand to close this file.


Sounds a little Rube Goldberg... I do not think you are telling us everything...

What is the program that is "getting data from a graphical user interface"?

Why is that CSV file the same name every time? 

 

I guess the easiest thing to do would be to copy the CSV file that is "getting data from a graphical user interface" to a new file with a new name and open the new file instead of the original CSV in the second program. You can copy a file that another program has open without any sharing violations. 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 9 of 39
(4,251 Views)

The file name can be changed or could be the same based on the operator's wishes. Thats not important. The GUI can append to a already existing file. But it can only write new data when the CSV file is closed. I only need to make sure the file is closed at the start of the program. Thats the problem, I am having.

0 Kudos
Message 10 of 39
(4,243 Views)