Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupting DAQmx, But Keeping Retained Data

Hello,

I've written several data acquisition programs using LV, and from what I've written, they can fall into two categories - 1) where I use the DAQmx functions and wait until the completion of the acquisition before the program continues, or 2) where I enter a while loop and sample a single data point (averaged from 20 or so) during each iteration.  With these approaches, there are limitations.  For the first approach, I must wait until the completion of the data acquisition before my program will continue, which makes it difficult if I would like to stop the test prematurely while keeping the data.  There are also issues viewing the data real-time while the test is being performed.  For the second approach, I can stop the program whenever I choose by exiting the while loop, but I am limited in how fast I can sample from the speed of the computer, and the sampling rate can be non-constant (definitely not ideal).

I know that I can program my 6009 or 6221 box to sample at a constant rate for a certain time (finite number of samples), but is there a way for me to interrupt the test and stop reading data without hitting the "stop" button altogether?  When I hit the stop button, I lose the data that I was reading, which defeats the purpose of having a data acquisition system.  Basically, if I have a test that I expect to take 10 minutes and I sample at a certain rate and select a finite number of samples that will take 10 minutes to acquire, but the test does not go as planned, can I exit the DAQ read without losing my data?  There has to be a way to do this, but looking through the commands, I have not been able to figure it out.
0 Kudos
Message 1 of 19
(4,935 Views)
Would not saving that ten minute data to a file on your Computer do the job??

Message Edited by devchander on 05-30-2007 03:53 AM

0 Kudos
Message 2 of 19
(4,930 Views)
"Would not saving that ten minute data to a file on your Computer do the job??"

Perhaps I did not explain myself thoroughly enough in my initial post.  Our goal is to establish a data acquisition system that we can use for long term testing at moderate sampling rates (say, 100-200Hz for now) using either a 6009 or 6221 box.  There are two ways of doing this using the DAQmx functions, which is what I'm using since they're relatively straight-forward.

Method 1:
Within a while loop which has a "Wait til next multiple" function, we initiate the box to sample a bin of data points (20 or so) at a very high sampling rate, average these values for our data point for that time, and then wait for the loop to execute this function again.  The problem with this approach is that when frequency gets to about 50Hz, the computer cannot execute the code fast enough, and we see an upper limit to how fast we can sample using this method.  Since we would like to sample at 100+Hz, this method is effectively out.

Method 2:
Instead of using a while loop and sampling effectively one data point at a time, we can use the DAQmx functions and sample a finite number of samples at a known rate, from which the total time may be easily calculated (samples/rate).  The benefit to this approach is that our sampling rate ceiling is determined by the box which is plenty high for both boxes.  However, the downside to this approach is that when the test is started, we must wait until the total number of samples has been acquired before the code will continue to execute.

Therein lies the problem.  If we have a test that we THINK will be 10 minutes long, but it turns out to be only 30 seconds, our options are to stop the test and forfeit the data from this first 30 seconds, or wait a full 10 minutes at which point in time, the code continues to execute and we can save the data using the "Write to Spreadsheet File.vi".

Thus, my question, is there a way that I can Interrupt the DAQmx Read function BEFORE it has completed reading all of the samples WITHOUT losing my data?
0 Kudos
Message 3 of 19
(4,894 Views)
Hello arkejellon,

I've read your post and have been trying to see what you are trying to do with your application. I can see that you are thinking of using our USB-6009 or USB-6221 devices to acquire data at 100-200Hz range. There are some subtle issues with your application I don't see, but here are some suggestions:

1) consider using a producer/consumer structure, where you are collecting data in the produced loop and placing the data on a queue structure. The consumer loop will then be used process the data that you collected. It will run while there is something on the queue. The queue operates similarly to a FIFO. Refer to the following resource to find out more about Producer/Consumer design structures.

Application Design Patterns: Producer/Consumer

This is type of design structure is used in all kinds of applications, for example, high-speed data streaming applications where they are sampling at 400MB/s.

2) use event structure to deal with execptions. For instance if a stop button press has been detected then you can have an event that would complete the read task and release the resources. Here is a tutorial on the issue.

Changing the Face of Design Patterns with LabVIEW 7 Express Event Structure


Take a look at these resources and see if you can leverage them in you application.

Regards,
  Sandra T.

Applications Engineer | National Instruments
0 Kudos
Message 4 of 19
(4,873 Views)

Just adding to the good suggestions from Sandra T.

The two options you outlined are NOT your only alternatives.  For example, let's consider what you called "Method 2" where you stated, "However, the downside to this approach is that when the test is started, we must wait until the total number of samples has been acquired before the code will continue to execute...".  That statement is only true if you call DAQmx Read while leaving the '# samples to read' input at its default value of -1, which is what happens when it's left unwired.  You could instead wire any smaller # N that you choose, and it will then give you the earliest N values.  (There are actually methods available to ask for the most recent N or some intermediate subset as well, but those don't seem necessary here.)  Something I've typically done is to call a DAQmx Read property node to query the '# of available samples'.  If I then request that # of samples (or less) in my call to DAQmx Read, I'll get them back immediately with no waiting. 

So... you can start your task using a buffer sized for 10 minutes.  Then if the operator determines that the test should be terminated after 30 seconds, they press the "Stop" button.  Your code can then call the DAQmx Read property node to query '# available samples' which you then wire into the call to DAQmx Read.  You'll immediately get back all the data taken up to that moment.  Then you can call DAQmx Stop or DAQmx Clear and the rest of your code will continue right away.

Sandra T's suggestions about producer-consumer and event-driven architectures would give you a framework for handling even more complex scenarios.  Good luck!

-Kevin P.

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Message 5 of 19
(4,829 Views)

Just adding to the good suggestions from Sandra T.

The two options you outlined are NOT your only alternatives.  For example, let's consider what you called "Method 2" where you stated, "However, the downside to this approach is that when the test is started, we must wait until the total number of samples has been acquired before the code will continue to execute...".  That statement is only true if you call DAQmx Read while leaving the '# samples to read' input at its default value of -1, which is what happens when it's left unwired.  You could instead wire any smaller # N that you choose, and it will then give you the earliest N values.  (There are actually methods available to ask for the most recent N or some intermediate subset as well, but those don't seem necessary here.)  Something I've typically done is to call a DAQmx Read property node to query the '# of available samples'.  If I then request that # of samples (or less) in my call to DAQmx Read, I'll get them back immediately with no waiting. 

So... you can start your task using a buffer sized for 10 minutes.  Then if the operator determines that the test should be terminated after 30 seconds, they press the "Stop" button.  Your code can then call the DAQmx Read property node to query '# available samples' which you then wire into the call to DAQmx Read.  You'll immediately get back all the data taken up to that moment.  Then you can call DAQmx Stop or DAQmx Clear and the rest of your code will continue right away.

Sandra T's suggestions about producer-consumer and event-driven architectures would give you a framework for handling even more complex scenarios.  Good luck!

-Kevin P.

 

How to you exactly "stop" and how to you call the DAQmx Rear property node to query # available samples?  I'm not sure how to path things correctly.

0 Kudos
Message 6 of 19
(4,461 Views)

Yin,

 

I think Kevin was refering to this property node that you can see in this picture:

 

 

A "Stop" button can be placed on the front panel and in the case Kevin described he would perform a DAQmx read based on when this button was pressed.  If you would like to do this also you would need to have that button connected to a case structure that will perform the desired operations in the true case.

 

If this does not answer your questions could you please be a little more specific about what you want to code and what you have tried.

Message Edited by Jason_D on 11-17-2008 09:36 AM
Sincerely,
Jason Daming
Applications Engineer
National Instruments
http://www.ni.com/support
Message 7 of 19
(4,433 Views)

jason;

what if i wanted to make an interruption for the Data acquisition and start it once i receive a rising edge at one of the device PFIs, for example i will continually acquire 6 channels , and once a rising edge occur i will restart the acquisition at this event and collect the data for example for 20 seconds. how can i interrupt the Data acquisiton process and restart it even if it wasn't finsihed yet (i usually need the number of samples 10 times the sampling rate which means 10 seconds for single acquisition.

note: i'm not interested in the data acquired before the rising edge

 

i found this thread very close to what i wanna ask about that's why i posted here

can you help in this

Thanks in Advance

Message Edited by MAshraf on 11-30-2008 05:20 AM
Eng. Mohammed Ashraf
Certified LabVIEW Associated Developer
InnoVision Systems Founder, RF Test Development Engineer
www.ivsystems-eg.com
0 Kudos
Message 8 of 19
(4,375 Views)

MAshraf,

 

I am not sure why we are using a continouous read if we are trying to read for 20 seconds.  We would simply perform a finite read triggered by the PFI line.  Why do we need to interrupt the acquisition?  I am still unsure as to your application so I cannot give you my recommendation, but it seems like a triggered finite read is what you need.

 

There is a DAQmx Reset Device if your question is solely how do I abort mid acquisition, but I would not recommend using this. 

Sincerely,
Jason Daming
Applications Engineer
National Instruments
http://www.ni.com/support
0 Kudos
Message 9 of 19
(4,345 Views)

Jason, Kevin,

 

I have programmed a one shot event that collects X number of data at Y frequency.  So you hit go and then data is collected for X/Y seconds.  Sometimes the data collection process will be 30 minutes long but the test can be finished in as little as 5 minutes.  I have tried using the property node but I am not sure where to insert it to get it to work.

 

I'm also not sure how to create an interrupt or even to get labview to read events before the data collection stops.   

0 Kudos
Message 10 of 19
(4,339 Views)