03-30-2010 11:26 AM
Hi:
I met a problem with saving data in labview.
I am writing this code to save the measurement data from a gauss meter every 3 seconds. The measurement is inside a for loop. I use the "write to spreadsheet" vi to save the data and it works fine.
The only problem is that sometime I want to stop the program earlier but the program wont save the data. I have to manually copy the array to a new vi to save it. I was wondering how to edit the program so that when I hit a "save" button it will save the data...
Thank you very much
Please take a look at my vi.
03-30-2010 12:22 PM - edited 03-30-2010 12:23 PM
Have you try converting the for loop to a while loop? i think you can simply right click on the while loop and "replace with while loop"
the for loop will go on until its finish with the loop, and the while loop will stop when you press stop. then it goes to the saving part of your code.
03-30-2010 12:32 PM
Since you're using a FOR loop, the only way to stop your code is by pressing the "abort" button at the top of the screen. When you do that, your program quits immediately. Therefore, the "Write to spreadsheet file" vi never runs under those circumstances. That's why your data isn't being recorded.
I can't remember who originally said this, but I think it's appropriate: "Using the 'abort' button to stop your VI is like using a tree to stop your car. It works, but there may be consequences." In other words, it is NOT good practice, and you shouldn't do it.
So. Replace your FOR loop with a while loop. Create a "stop" button. Compare the iteration terminal (decremented by 1, since the iteration terminal starts at 0) to the number of times your loop is supposed to iterate. OR that comparison with the "stop" button.
See attached.
I've cleaned up your block diagram somewhat as well....your wiring is a mess. It may not seem important, but it is. It's very important from a readability standpoint.
Hope this helps...
d
03-30-2010 12:40 PM
I can't Diane S. vi because I dont have Labview 2009 installed right now.
But the old vi that you made seems to collect data and store it in an array.
but if the program is running for a couple of days, you might run out of memory to store into the array.
so i think you can do this?
save to the file as you go along.
03-30-2010 12:58 PM
Hello,
I could see in the code, that you have shift register for the 2D array which is of no use, you have not used to store all the values. THis 2D array you are using to write into spreadsheet, I believe your spreadsheet stores only the last data and not the entire data,
There is no way to stop For loop unless using abort button (exceptions from LV 8.5), as said by others replace that by While loop and use stop button to stop program when needed.
03-30-2010 01:01 PM
03-30-2010 01:23 PM
Cancancanopen, if you just replace the shift register with a tunnel, you will see that all of the data is getting recorded. (you are quite right that the shift register right there is completely pointless and should be replaced with a tunnel -- good catch). The new data is actually being added via the other three shift registers, and then those arrays are being built into a 2D array. So the 2D array does contain all of the data.
The OP does calculate how many times he wants the loop to run, so the array size is bounded (krispiekream eliminated that part of the code in his modification -- it is still present in mine, and my while loop will automatically terminate after the correct number of data points has been obtained). It was originally a FOR loop, remember? That being the case, from a memory standpoint it would make better sense to preallocate the arrays and then use "replace array subset" to fill them in with each loop iteration.
I agree with Mark that you want to be careful about having your file write and your data collection in the same loop, especially if you are opening and closing the file every time you write to it. He is of course correct that the right way to do this is using parallel loops and a queue.
03-30-2010 01:30 PM
Yeah, you guys are right about this "You can accomplish this using a parallel loop and use a queue to pass the data to be written from the data acquisition task to the one that will write the data to file."
I am still learning labview so I would love to see it in a block diagram?
I dont know how to use a queue yet, but I want to learn.
03-30-2010 01:34 PM
Hello Diane thanks, I overlooked the array building.
Rest of the things regarding memory consumption, I am in agreement with you guys.
03-30-2010 04:06 PM