05-26-2015 11:59 AM
Hello all,
My first question about writing to text file is does the file need to be opened? i know you have the option to create, replace, open..., but does it need to be opened in order to properly write data to the file? Also if my application is running with a disk streaming file setup and i open the file that it is writing to will this cause an error or cause labview to lose control of the file and possibly stop writing to the file?
Thank you,
Matt
05-26-2015 12:08 PM
Feel free to experiment. Try writing to a file from multiple locations at once, and you'll see race conditions where data could be lost.
The reason for the Open, Write, Close type of software is because generally you are in a loop continually writing to a file, and the extra overhead of a Open and Close can be limited to when the software starts and closes, instead of having to open a new reference and close it every time you want to write to the file. Just open the reference once, work with it in a while loop, then close it once, must more efficient and better for applications that write many times to disk.
Is it necessary? No you can just use the Write to Text file giving it a path and data to write, but behind that function it will need to open and close the reference each time.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
05-26-2015 12:27 PM
If streaming to a file, you need to do the Open/Write/Close setup. Constantly opening and closing the file is slow. Plus, if you just use the Write Text File, I think you will end up overwriting your data with each write. Not something you will want to happen.
Opening with another program completely depends on the program. I have had success opening a text file with Ultra Edit while still streaming data to it with my program. Excel caused errors. Your mileage may vary.
05-26-2015 12:38 PM
Ok,
I guess my real question is when using open/create/replace block do i need to use it twice before the loop, such as create or replace, and then an open? I have attached my VI that i use before my write to text loop, is the extra open/create/replace block overkill?
THank you,
05-26-2015 12:48 PM
My other question about opening the file was if i manually opened it in with notepad or something, would i see an error if it was no longer able to write to the file or would it just continue to try with no error?
05-26-2015 12:57 PM
You should not need to open the reference twice. Just open it once and use that reference remembering to close it when you are done. I know you probably just attached an example VI but what posted is particularly bad because you don't close either of your references.
If your file exists and you want to replace it or create a new file if it doesn't exist, you can use the Replace or Create. If your file exists and you want to append data to it, or it doesn't exist and you want to make a new one you can use Open or Create.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
05-26-2015 12:58 PM
@matt198717 wrote:
My other question about opening the file was if i manually opened it in with notepad or something, would i see an error if it was no longer able to write to the file or would it just continue to try with no error?
That depends on the application. Notepad doesn't lock the file. So if you are writing to it and you open it in notepad LabVIEW will keep writing to it no problem. But Excel does lock the file, and when you try to write to it, LabVIEW will return an error on the write function.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
05-26-2015 01:28 PM
Thank you Hooovah,
I do close the reference after the data has been written. The vi i attached was just the initializing vi.