LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

daqmx blocking while loop

I have implemented a state machine, and in one of the states I am using Daqmx to acquire data that is triggered with a reference analog edge.  The problem I am having is that DAQmx Read VI is blocking my state, and I cannot get it to exit if I click a button to move to move to a different state.  This is my first time using DAQmx VIs (I usually use Daq assistant if possible), so I may be missing some advanced setting that will do what I need.  I am acquiring data with a PXI Chassis with LabView 15.

 

The data that I am recording is for a very shot duration event, only a few milliseconds long, so I need a very high sample rate.  I NEED to use a Reference Analog Edge Trigger because I need to know the voltages of these signals for a few sample before the actual trigger.  I cannot change this requirement.

 

I also realize that I could set a timeout on the DAQmx Read so that when it timeout, I can check the status of my buttons, and then restart the DAQmx read function if my button is not pressed, but there is a small chance I could miss the event trigger if I do this, and I cannot take this chance.  That is why I have a -1 wired to the timeout input of the DAQmx read VI- I cannot afford to miss this very short duration event.  But I do need to be able to change states using a button if I know for some reason after the fact that the event will not be occurring after I already started the task.

 

I have attached a very simplified version of this problem using the same DAQmx settings, then I enter a loop with the DAQmx Read VI.  I want to be able to exit this loop if I press the stop button, but I cannot find a way to unblock the DAQmx Read function.

 

Thanks for your help!

0 Kudos
Message 1 of 6
(4,139 Views)

Hi Navygun,

 

You put -1 as timeout. your function will wait indefenetly til you got a trigger. You should put another value in ms.

 

Regards

Sabri JATLAOUI - Certified LabVIEW Architect - Certified LabVIEW Developer
0 Kudos
Message 2 of 6
(4,131 Views)

Sabri, you did not read my problem statement.  As I said, I do not know when the trigger will occur, so I could miss the trigger and the event if I timeout to check the status of buttons and other variables, as this event is very short. 

0 Kudos
Message 3 of 6
(4,125 Views)

I found another forum where someone is doing something very similar:

 

http://forums.ni.com/t5/Multifunction-DAQ/Stop-infinite-timeout-DAQmx-Read-task/td-p/204008

 

Based on this, I am trying to use the DAQmx Read Property node to check if the Available Samples Per Channel equals my requested sample per channel.  If this is true, then I call the DAQmx Read VI, otherwise I keep waiting until the Available sample per channel is correct.  I also check the stop button, and if it is true, then I stop the task.

 

I have implemented this in my new version of my VI.  Please let me know if anyone sees any issues.

 

Thanks!

 

0 Kudos
Message 4 of 6
(4,120 Views)

1. Move your Stop button into the inner loop and change its mechanical action back to "Latch When Released".  You can pass its value to the stop condition of the outter loop as well.

2. When checking for data, just use the Greater Than 0 function.  This way the loop stops when you have your trigger and then you can just let the DAQmx Read complete when all of the data has come in.

3. Move your DAQmx Stop to be after the case structure.  No point in having it in both cases.

4. You do not need to stop your task before it is even started.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 6
(4,098 Views)

I can't see your code because I am on my phone, but if your hardware supports it a solution might be to create a DAQ event that fires when your input signal passes through whatever threshold you have defined. This DAQ event can be handled in an event structure like any other event.

As far as the state machine goes, include that in the event structure in the timeout event. I show this structure in this post and the one following.

http://www.notatamelion.com/2015/02/23/building-a-proper-labview-state-machine-design-pattern-pt-1/

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 6 of 6
(4,090 Views)