LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems getting data to continuously write to text file in spreadsheet format.

I have a simple system with eight random number generators. I am attempting to get the readings (in zero's and one's) to write to a spreadsheet format. I have tried many things, but the way I have it hooked up now, it will only record the last set of data (before the program is stopped). How can I get all my data? (see attached vi)
0 Kudos
Message 1 of 6
(4,684 Views)
You only hand data from the while loop to the write when the while loop is terminated...that's the way data flow works (nothing exits the loop until the loop is terminated...and it's only the data from the last iteration that exits, unless you keep the previous data in a buffer in e.g a shift register).

If you want to write the data from each iteration you need to either put the string building and file write function inside the loop, or build a 2D array of all the 1D arrays you generate and then write that 2D array when the while loops finishes...(in the latter case it's best to initialize a shift register with a 2D array of the correct size and then replace rows/columns inside the loop...not build the array on each iteration as that requires continous memory alloca
tion, which is memory costly and slow...).

If you decide to write on each iteration I would recommend not using the write characters to file function as this opens and closes the file every time..insetad open/create the file prior to entering the while loop, write on each iteration and then close when the while loop terminates...(if the loop is to run a lot of times it may be possible to optimize performance by combining the two approaches; keep X iterations in memory and just write on every X itertaion...).
0 Kudos
Message 2 of 6
(4,684 Views)
Turn autoindexing on for the output of your spreadsheet string through the while loop. That way you'll have an array of strings instead of just the last one created.
0 Kudos
Message 3 of 6
(4,684 Views)
A common mistake. Your while loop runs just fine, but the data that you want to write will only come out of the while loop when the loop stops; then only the last value will come out.

There's really two ways to do it; you can write the values every time the while loop iterates by moving your "write" code into your while loop. Or, you can use a shift register on your while loop, and wire a "build array" (in Array palette) output to the right side shift register. Wire the top input of the build array to the left shift register, and the bottom to your data.

Wire the output to your "write" code.

You'll want to wire an empty array into the left shift register to initialize it to empty when your loop starts.

Hope that helps.

Mark
0 Kudos
Message 4 of 6
(4,684 Views)
you want to set the Append to File Flag TRUE on your Write characters to file, that will write the characters on the next line of your file. I modified your VI, look on the block diagram for text description hints.

dhuff

You have a neat front panel image by the way.
0 Kudos
Message 5 of 6
(4,684 Views)
Thank you SO much. I really appreciate it.
0 Kudos
Message 6 of 6
(4,684 Views)