12-13-2012 04:56 AM
Need to gather data from various sources, 6 lines in total and average values over 30 seconds. So I have used a 2D array with 6 x Insert into array functions and shift registers on each to fill the array. I have used an elapsed timer to activate a case statement around this lot that clears the arrays after 30 seconds and then re-starts gathering next block of data. This does work fine, but.....
The question I have is that the code looks overly complicated and a mess. I have tried indexing with for loop and while loops etc but the data enters the loop and the loop only 'grabs the first lot, ignoring the rest so the array gets filled with the same value, I know this is obvious really given the rules of loops etc.
It feels like there is a much better way of doing this, any suggestions to a neater method?
Solved! Go to Solution.
12-13-2012 05:00 AM
It would be better if you can attach the vi.
12-13-2012 05:09 AM
Oops missed that, sorry...
Basic idea but without timer, summation etc
12-13-2012 05:45 AM - edited 12-13-2012 05:56 AM
You are initializing the array with a size of 10, you really don't need it becuase you are simply inserting the new elements to the array its nothing but building the array. Since you are inserting array and then building everything again to a 2D array all the time you are duplicating the values so it will eat up the memory and you will end up in memory leakage error. What you can do is initialize a 1D array in the initialization with the number of channels and in all the iterations just replace the values with the new one, so you will always have the latest single value of all the channels. Al the same time write the array to a queue. In other place where you want to log or display the data you can read the data and also you can log it easily by reading the queue.
Edit: Sorry I forgot your 30 second average requirement. This decides how much of data you can hold in memory and also it depends on the rate at which you acquire the data. If you can give those details it would be good.
(Correct me if I am wrong)
12-13-2012 08:10 AM
Because I can make all of the data to be logged available in just one while loop I have taken the EnQueue loop and placed it inside the main while loop where the case statement now also resides. The Enqueue loop only runs once (as per your diagram) but I have removed the Queue elements.
The main loop runs at 150 milliseconds and I will probably gather data for around 8 seconds, worst case would be 30 seconds which I make to be 200 points?
It works fine though and does look a lot neater,
Many thanks
Jack