LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

file i/o inside a loop

I have a loop which will be collecting data from some sensors each time it runs, and I want to write the data to a file inside this loop. My question is that if an error occurs during normal program execution, such as the program crashing or the computer crashing or something else that would cause labview to not be able to reach the part of the program where it closes the file. Will I be able to see the data that was written throughout the loop even though labview never closed the file reference. This is important because the program will be running for a very long time so waiting until the end of execution to write the data is not possible, as the data needs to be made available on the hard drive sooner than that, and obviously opening/closing t
he file each time would be resource intensive. I don't know how labview handles writing and moving the eof pointer and such, so could someone please help me with this? Thanks
0 Kudos
Message 1 of 5
(3,504 Views)
Unless LV crashes in the midst of writing to a file it should be ok. Most modern operating systems are pretty forgiving about leaving files open when a program quits "prematurely".

If LabVIEW does crash in the middle of a write, the last update would be trashed, but everything else should be ok.

Finally, unless you create one yourself there is no EOF marker on LabVIEW files.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 5
(3,503 Views)
To play safe writing to a file for a long period of time you should:
- when opening the file, set the deny mode to 0 (deny read/write). That will prevent other applications (FindFast, antivirus, backup) to access the file simultaneously causing you write errors. By default, files are opened allowing simultaneous access to other apps. If you need that already written data be available, use "deny write-only" but make error checking in case write errors occur (just retry until no error).
- use the advanced file function "Flush File" once in a while. That will force any file buffer in memory to be written on disk and update the directory entry of the file. The file stays open.


LabVIEW, C'est LabVIEW

0 Kudos
Message 3 of 5
(3,503 Views)
Does flush file do this for all files that are being written even though they may not be directly connected to the vi in which the call is located? I will most likely have several sub vi's which will run in seperate and independent loops, and will all be writing to independent files. Do I need a flush file in each sub vi, or can I just put one in the main vi?
0 Kudos
Message 4 of 5
(3,502 Views)
Flush File function requires a file refnum to operate, it works on one file at once,


LabVIEW, C'est LabVIEW

0 Kudos
Message 5 of 5
(3,502 Views)