11-20-2013 06:36 PM
I am working on a thermocouple measurement VI. The code will read the thermocouple readings in a while loop, and there is a case structure inside the while loop box that has a "build an array" function in it. That will collect the data only if the case structure is true. Then by placing "write to spreadheet" vi outside of the loop, the data collected will be saved to a spreadsheet file.
The problem that I'm having is, for every "false" case, it will return zero values and "write to spreadsheet" will also record those values. Clearly I am not interested in the readings when the case structure is false. I'm guessing the problem might come from the fact that I checked "default if unwired" option, but I'm not sure how to fix that. I also tried to put the "write to spreadsheet" vi inside a case structure which is also controlled by the same save button, but that doesn't fix it.
11-20-2013 06:47 PM - edited 11-20-2013 06:49 PM
Hello Saiful.hk,
If you're using 2012 (which it looks like you are), the "easiest" (as in working in three clicks) option is to enable the conditional terminal on your auto-indexing loop tunnel and connect the "save" control to the conditional terminal. Right-click on your tunnel and select the option there to enable conditional indexing.
However, if this application is intended to run for any significant period of time (how long this is is somewhat arbitrary, since you're only sampling on one channel it could be a while before you hit trouble), I would strongly recommend that you take the time to implement a simple state machine that buffers data and saves to file periodically- if left unwatched your auto-indexed while loop tunnel could easily grow indefinitely until your computer (or LabVIEW) runs out of available memory.
Regards,
11-20-2013 07:08 PM
Another approach which eliminates the growing array and the memory re-allocations is to use Replace Array Subset. First initialize an array outside the loop to a size larger than the maximum size your array will ever reach. Inside the array use Replace Array Subset to put new data into the array by overwriting the initialized data rather than expanding the array. Keep track of how many replacements have been done. After the loop use Array Subset to trim off the part of the initialized array that was never replaced. Save the trimmed array.
Note that I disabled the DAQ and file VIs to test the VI. Also note that I arbitrarily chose 1000 rows as the maximum size.
Lynn
11-20-2013 11:57 PM
I have made some changes in your VI using OpenG functions. Hope it works on your system.