09-20-2013 09:39 AM
I am trying to use DAQ-mx to continuously monitor an analog input from USB-6009. Essentially I am following ContAcq-IntClk-AnlgStart.c in the NI examples. The change is that I want to terminate the acquisition using "DAQmxStopTask" within an if statement in the call back function instead of using "getchar()". However, after that change was made, the program will terminate before any reading is done. It looks like the purpose of "getchar()" in the example code is essentially to hold the program while the task is still active. But I do not want to press the Enter key in response to "getchar()". Please let me know if there is anyway to wait until a continous acquisition is ended without resorting to "getchar()". Thanks.
09-23-2013 12:04 PM
Hi Wait,
Thanks for using the Discussion Forums! From the ContAcq-IntClk-AnlgStart.c example I have, there is no getchar() function being called. Could you upload your code to take a look at it?
09-24-2013 10:57 AM
Hi Dan
Please find the attached file. Thanks for looking into it.
Wait
09-25-2013 11:18 AM
Hi Wait,
As you said, the getchar() is there just to wait until a user interaction is made, which is totally expected. If you would like to call the DAQmxStopTask, I suggest you use an if statement inside a while loop so the program knows when it's supposed to stop acquiring. What you need to ask yourself is, what variable will break the loop so the program continues to the "DAQmxStopTask".
Let me know if you have further questions.
09-25-2013 03:25 PM
Hi Dan
Thanks for looking into it. But what you suggest about the DAQmxStopTask is exactly what I did in the file uploaded. In the EveryNCallback function, I call EveryNCallback if the total number of data read reaches 50. The issue of removing getchar() is not that the task is never going to be terminated but that task is terminated right at the beginning! For a finite measurement task, DAQmx has a function to wait until done. Is there anything similar for a continuous task?
Wait
09-27-2013 08:03 PM
Hi Wait,
I guess what I'm having problem seeing is why make a continuous acquisition if you don't have a user input that stops the acquisition. If you have a fixed amount of samples you want to read, you might want to try using a finite acquisition.
09-30-2013 09:57 AM
Hi Dan
It is merely for testing purpose that I set the exit condition to be some fixed amount acquired data. The original purpose of the code is to monitor the signal and to stop acquisition once the signal surpasses a certain value. To achieve the original purpose, I am still looking for a way to wait until done.
Wait
10-02-2013 02:27 PM - last edited on 08-09-2024 01:44 PM by Content Cleaner
Hi Wait,
If that's the case, you might be interested in looking at the "Acq-Int Clk-Dig Ref" example. Basically, the program will start acquring in a round-robin FIFO, writing the samples. When the buffer is full, it will start overwriting the previous values. We will be continuously acquiring until the reference (stop) trigger has met the condition. When that happens, DAQmx will present the samples contained in the PC buffer at the time.
The difference between this and monitoring a value is that the reference trigger is a hardware-timed operation. So you can be certain that you're stopping the task as soon as the trigger condition is met. You will just need to change the trigger type from digital to analog on the shipping example. The source of the analog trigger you want could the same physical input channel you are reading on your AI task. This is a good way to test out the reference trigger.
There are some whitepapers that talk about it here and here.