LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

writing to a file using labview

hello,
so i wrote this vi to write some data to a text file and that part works correctly.

the problem i'm having is that, it doesn't append to the file. so for each data point that it writes it requires a new file.
in otherwords, if i need to write 10 data points the program prompts each time for 10 different file names.

how do i resolve this so that the program will write all the 10 data points to one file, by appending each time.
e.g. data points: 29.5, 34.2, 21.34, 543.2 ... etc

i want something like this:
29.5
34.2
21.34
543.2
etc

thanks
-r
0 Kudos
Message 1 of 11
(3,599 Views)
In Labview go to help then click on "examples� then search for �write�
0 Kudos
Message 2 of 11
(3,599 Views)
What do you use to write to file? Most file I/O tools have a terminal labeled "append?". Wire a "true" boolean constant to it, except for the first write. See if this helps.
0 Kudos
Message 3 of 11
(3,599 Views)
heritage,
i did a search for "write" using the help menu. it too doesn't append to file. it writes to several files, just like mine.

also i couldn't open the file that you sent because i'm using labview 7.0 (file was save in 7.1). if that file is different from the one in the "help menu" then can you please post it again, this time saved in 7.0?

thanks
-r
0 Kudos
Message 4 of 11
(3,599 Views)
i used "write character to file.vi" to do the writing. i wired the "append" to "TRUE".

my question is this. how to i make that exception so that the append will be false if file is new (or first write)?

everything works, except that it writes to the same file (say twice) and prompts me for another file. i don't want that. just take 1 file and keep appending until it runs out of data or EOF.

-R
0 Kudos
Message 5 of 11
(3,599 Views)
Oh its was and example in the help VIs I can't send the file because I am at home but its just and example that comes with LABview.
I will work on a better example for your problem in 12 hours. If you fix it then please post but search online for example or post the VI.
0 Kudos
Message 6 of 11
(3,599 Views)
If the path is correctly wired, it should not prompt you for another file. Make sure you wire the path to a shift register so it is available the next time the "write charaters ..." is called.

You can do the "exception" in many ways. Some examples:

--Check if the file exists, and if so, append.
--Use a shift register initialized by "false", then wire it to the append terminal. Feed a "true" to the shift register on the right.
-- ...

However, you should consider using some of the lower level file I/O and open the file only once, then keep writing data and close it only at the end. The high-level "write characters to file" would need to do a lot of extra work because whenever it is called it opens the file, writes/appends data, then
closes the file again.
0 Kudos
Message 7 of 11
(3,599 Views)
altenbach,
you nailed it! you were soo right. i needed a shift register ... now it's working.

so at this point, my program works by taking a specified (currently 20) data points (number of points). what if i want it to keep doing it indefinitely? i want it to keep doing it as long as the machine or the operation is running.

i was thinking about wiring it to a constant (say 2000) but then the actual operation might end up producing more than 2000 data points and so i'll end up losing anything after 2000.

how do go about this?
-r
0 Kudos
Message 8 of 11
(3,599 Views)
If you don't know the number of iterations in advance, you need to use a while loop. It will keep going until the loop condition changes state so just wire a stop button to it that you can trigger at will.
0 Kudos
Message 9 of 11
(3,599 Views)
so then what happens if i don't trigger the stop button but the operation is done or the machine stops running?

will this automatically end the loop?

-r
0 Kudos
Message 10 of 11
(3,599 Views)