Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Wait until a continuous acquisition is ended.

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.

0 Kudos
Message 1 of 8
(6,154 Views)

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?

Regards,
Daniel REDS
RF Systems Engineer

Help us grow.
If a post solves your question, mark it as The Solution.
If a post helps, give Kudos to it.
0 Kudos
Message 2 of 8
(6,136 Views)

Hi Dan

 

Please find the attached file. Thanks for looking into it.

 

Wait

0 Kudos
Message 3 of 8
(6,126 Views)

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.

Regards,
Daniel REDS
RF Systems Engineer

Help us grow.
If a post solves your question, mark it as The Solution.
If a post helps, give Kudos to it.
0 Kudos
Message 4 of 8
(6,115 Views)

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

0 Kudos
Message 5 of 8
(6,111 Views)

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.

Regards,
Daniel REDS
RF Systems Engineer

Help us grow.
If a post solves your question, mark it as The Solution.
If a post helps, give Kudos to it.
0 Kudos
Message 6 of 8
(6,089 Views)

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

0 Kudos
Message 7 of 8
(6,068 Views)

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.

Regards,
Daniel REDS
RF Systems Engineer

Help us grow.
If a post solves your question, mark it as The Solution.
If a post helps, give Kudos to it.
0 Kudos
Message 8 of 8
(6,048 Views)