06-06-2017 08:20 AM
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?
06-06-2017 08:50 AM
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
06-06-2017 08:54 AM
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.
06-06-2017 09:09 AM
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.
06-06-2017 09:12 AM
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?
06-06-2017 09:13 AM
I guess it's time to show the code you have. It seems too complicated to explain a few sentences.
06-06-2017 09:13 AM
@crossrulz wrote:
I am even more confused now.
Guess it wasn't just me
06-06-2017 09:14 AM
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.
06-06-2017 09:17 AM - edited 06-06-2017 09:20 AM
@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.
06-06-2017 09:20 AM
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.