LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

reading data out of while loop

Solved!
Go to solution
Highlighted

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.

cdaq-io-config.png

Thanks!

Download All
0 Kudos
Message 1 of 7
(490 Views)
Highlighted
Solution
Accepted by topic author beneeto

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.)

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2019 sometimes) on Win10+cRIO
Message 2 of 7
(427 Views)
Highlighted

@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

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 7
(373 Views)

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.  

 

producer-consumer-snip.pngread-data.png

0 Kudos
Message 4 of 7
(332 Views)
Highlighted

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?

 

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2019 sometimes) on Win10+cRIO
0 Kudos
Message 5 of 7
(323 Views)
Highlighted

You stop the DAQ read if you get an error, which most proably generates no data ...

/Y

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 7
(319 Views)
Highlighted

Thanks again.  I got the queue working after reviewing and addressing points you made in the last post.producer-consumer-snip.png

0 Kudos
Message 7 of 7
(296 Views)