05-18-2020 01:49 AM
Hi NI Community,
I'm building a program to collect data, save data as the program is running, and process data. I'm trying to see if I could have 1 Producer loop that sends queue data to 2 or more consumer loops where each consumer loop does a different task. Is this possible? If so, what is the best way to implement it?
For example:
Producer loop collects data -> Consumer loop 1 receives data and save TDMS
-> Consumer loop 2 receives data and do basic data processing and display on the screen
Thank you!
05-18-2020 01:57 AM - edited 05-18-2020 01:58 AM
Hi Victor,
@victor55 wrote:
I'm trying to see if I could have 1 Producer loop that sends queue data to 2 or more consumer loops where each consumer loop does a different task. Is this possible?
Yes.
Use two queues!
(Or a queue for data saving and a notifier for UI display…)
05-18-2020 05:33 AM
Another option is to use User Events. You just have your consumer loops register for the event and each one will get a copy of the event. It is a little more extendable than multiple queues.
05-18-2020 08:08 AM
I had a colleague who generated 10" videos, 24 at a time, continuously for 2 hours, needless to say consuming huge amount of disk space. Trouble was, just after he generated an AVI, he determined (through other sensors) whether it was worth keeping (about 1% were kept). To prevent a Hard Drive Embolism, he had a separate routine that he passed the file names of the "files to be deleted", but it just wasn't fast enough.
I suggested a Producer/Consumer, which at least let the DeleteMe routine run in parallel with all of the Writers. Still not fast enough. So I said "Send the Queue to four DeleteMe Routines", which did the work in parallel, roughly 3-4 times faster. Then I convinced him to change the algorithm -- instead of "Save First, Decide if Useful, then Discard as needed", try "Acquire, Decide if Interesting, and if so, Start Saving" -- since these were Videos, we could use IMAQdx's Buffers to save, say, 1" of data before the "Event Start" signal was detected, so could Have our Cake and Save It, Too.
Bob Schor