Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Detect end of asynchronous write

I have an aschrynous output task and I need to know when it is DONE writing the data each time. As an example, I made a Stopwatch (called sw) and started a continuous analog output task which has a sample rate of 1000 samples a second, then I ask it to output data[200], which is a 200 ms signal. (pseudo-code below, I'm using c# and daqmx)

 

stopwatch.Start()

OutputTask.BeginWrite( true, data[], AnalogOutCallBack, null)

 

...

 

private void AnalogOutCallback(IAsyncResult ar)
{
writer.EndWrite(ar);

MessageBox.Show("Waited " + Convert.ToString(stopwatch.ElapsedMilliseconds) + " ms, should have waited 200 ms" );

}

 

The messagebox says it waited like 30 ms when the output signal was like 200 ms, which means this AnalogOutCallback is being called before it's done writing data[]. Is there any way to know when all the data[] is written? It seems to me like the AnalogOutCallback is immediately called after BeginWrite and EndWrite isn't doing anything. I can't Start and Stop the task because my application requires this to repeat at 20 Hz, so I think asynchronous and continuous is the way to go. 

 

Thank you!

Chris 

0 Kudos
Message 1 of 4
(3,250 Views)

Hi chrisgiardina,

 

Have you tried looking into some examples and tutorials for DAQmx Text-based?

 

I am seeing in the NI page that there are a lot of examples that can be useful for you in order to achive what you are trying to do. Follow this links:

 

https://www.ni.com/en/support/documentation/supplemental/21/using-ni-daqmx-in-text-based-programming...

 

http://www.ni.com/example/6999/en/#C.NETandVisualBasic.NETVB.NET 

 

Regards,

0 Kudos
Message 2 of 4
(3,218 Views)

Hi David,

 

Thanks for the advice - I looked around and I found an example that is almost exactly what I want - exept it only does analog input. I need it to do analog output AND input at the same time.

 

This is the example: http://www.ni.com/example/27345/en/ 

 

Any idea of how to get the BeginRead and BeginWrite to begin at the same time when asynchronous?

Thanks!

Chris G

0 Kudos
Message 3 of 4
(3,214 Views)

I am not very familiar with DAQmx using text-based, but I know there is a really good tutorial about to synchronize your different tasks using DAQmx functions. Take a look at this one, hope this helps for you.

 

https://www.ni.com/en/support/documentation/supplemental/06/timing-and-synchronization-features-of-n....

0 Kudos
Message 4 of 4
(3,210 Views)