08-22-2019 07:58 PM - edited 08-22-2019 08:01 PM
I'm running a while loop and using the DAQmx functions to read cDAQ analog inputs. I'm attempting to create subVIs to organize the code. The while loop runs continuously until i stop the program manually. In cdaq-io-config.vi the array called analog-data inside the while loop gets executed, but passing this data to the main-program.vi doesn't get executed. What's the proper way to handle this? I will likely need to setup another couple of tasks as well as some TDMS file functions. I don't expect those would need to live inside the while loop. Do i create a queue so i can work asynchronously? I read something that said i can create local variables (outside of the loop?) to do this as well but haven't had any luck with that.
Thanks!
Solved! Go to Solution.
08-23-2019 12:57 AM
Hi benneto,
What's the proper way to handle this?
When you want to implement a producer-consumer scheme you should employ queues/notifier/channels.
(All those bolded items are explained in example VIs and projects, which come with LabVIEW.)
08-23-2019 04:33 AM
@beneeto wrote:
Do i create a queue so i can work asynchronously? I read something that said i can create local variables (outside of the loop?) to do this as well but haven't had any luck with that.
Yes, you send the data to a queue or an event that you catch in the main.vi
/Y
08-26-2019 08:36 AM
Thanks for the advice. I think I'm close but am still having trouble getting data out of the while loop. I reworked things using a Producer Consumer Design Pattern Template (Events). My read-cdaq-io.vi is inside of the enqueue element. I start by toggling the bool inside the enqueue element and then i can see data being read inside the while loop of the read-cdaq-io.vi. The wire coming out (analog-data) of that vi is still not being executed and as a result no data is being enqueued.
08-26-2019 09:07 AM
Hi benneto,
THINK DATAFLOW!
Answer that question: When will (according to DATAFLOW) the data be available in the producer loop of your main VI?
There should be no "default if unwired" tunnels with reference wires!
Why is there an event structure?
Why do you read waveforms for just one sample per channel? Why do you wire waveforms to an array indicator?
Why do you create a queue with a variant as datatype?
08-26-2019 09:09 AM
You stop the DAQ read if you get an error, which most proably generates no data ...
/Y
08-26-2019 03:50 PM - edited 08-26-2019 03:50 PM
Thanks again. I got the queue working after reviewing and addressing points you made in the last post.