LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get array of data from while loop after each iteration

I am trying to make a simple VI that instantly fills a 2D array with random numbers -999 to 999 every second (mimicking data acquisition). I used two for loops to create the random arrays and a while loop for the process. That part works perfectly. My problem is that I want to get the array from the while loop each second and put it through a subvi that will analyse the array line by line and then spit out a new 2D array with the refined data. From there I want to plot each refined array line by line. This all should be simultaneous. My problem is that I can't get the data from each while loop after each iteration so the random numbers are being generated every second in the array but of course I can't get them out until the while loop stops. Can someone provide an example of how I might accomplish this?

Some background:

This is a test for a larger application where data will need to be acquired in one subvi, either analysed in another subvi (if the user wants to do so, if not, raw data will just be plotted), and plotted after analysis in another subvi for up to 6 inputs simultaneously, so I don't think I can simply but everything in the while loop. In addition, the user will be able to apply calibration, and control different acquisition settings so data will need to be passed between multiple subvis simultaneously.

 

I attempted to use Notifiers (I've never used them and don't completely understand them but I saw an example where they were used for a similar purpose). I kind of threw it together into a vi for you to get a basic idea of what I'm trying to do. But like I said, I can't get the array every second from the while loop. I took a screenshot because unfortunately I can't post the subvis that go with it.

0 Kudos
Message 1 of 5
(3,496 Views)

Your notifier setup is not going to work because they are not connected (you have two separate notifier instances). I recommend using a queue for this. Enqueue a new element on each iteration of the top loop and have the bottom loop work through the queue as they come.

 

For further guidance on queues, go to Help > Find Examples in LabVIEW and search for "queue". Simple Queue.vi is a great starting point.

 

If you still need help and return to the forum, please attach actual code or at least a snippet rather than a picture. Good luck.

Message 2 of 5
(3,489 Views)

Since your notifiers aren't named, you are actually creating (obtaining) two different notifiers.  You only need to create one and share the reference between the two loops.

 

Edit: And Dave is right, a queue would be better for this.

Message 3 of 5
(3,487 Views)

You've got a few decisions to make.

 

First, let's take a look at why people are suggesting you use queues instead of notifiers.  They behave similar.  You pass the reference to both places, feed values in one, and read elsewhere.  But, a notifier can only hold the most recent value.  That means if you write to it two or more times in the time it takes to read and process elsewhere, you'll lose data.  I doubt you want that if you're trying to simulate data acquisition.  Instead, you use the queue so it maintains each of the entries until they're consumed and will do its best to catch back up if you ever fall behind.

 

Second, you currently have to wire the iterations data somewhere to be able to get the entire 2D array at the end of the while loop.  If you want a subVI to process this data, it's trivial to add it just before this point.  If it's the last thing on the wire that happens in the iteration, it'll still happen "after the iteration" so to speak.  I wouldn't really suggest this as that slows your acquisition rate down to the period required to sample and process the data.  You're better off looking at the producer/consumer idea (again, queues) that you've already started to explore.

 

Third, how long will this acquire?  If it's for any meaningful time, you'll quickly be coming back here to troubleshoot your "memory leak" you're seeing.  People will look at your code and point out it isn't a memory leak.  Rather, it's unbounded growth.  If you store ALL of the data you acquire in memory, you'll quickly grow your memory to untenable sizes.  Do you really need to have immediate access to all of your data?  If not, consider adding some file I/O to store off older values into a file somewhere and allow it to be purged from memory.  This will allow your acquisition to run longer as you won't hard cap yourself on available memory.

Message 4 of 5
(3,429 Views)

Thank you all so much! That gives me a much better idea of where to start. As for the time it will acquire, it should be able to acquire for long amounts of time and update a waveform chart as data is acquired because the user will want to see it in (approximately) real time. I already give the user the ability to save data to a file as its acquired so maybe I could make it so that each time the graph updates it stores the older values to a file regardless and if they don't want to save it deletes the file when acquisition stops?

I'll give some additional background I forgot to mention: the code I'm updating works as it is right now, it will calibrate pressure data and will call an .exe to analyse data as its acquired. The only issue is the coder who created (who unfortunately no longer works here) used a lot of weird workarounds and tricks to get LabVIEW to work just right. My task is to go in and change a call to the .exe to a call to a .dll with a better analysis algorithm, which seems simple enough but its turned into a nightmare and basically the entire program needs to be rewritten. So that's why I'm exploring better ways to handle the data.

0 Kudos
Message 5 of 5
(3,412 Views)