07-11-2016 07:14 PM
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
07-13-2016 10:11 AM
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:
http://www.ni.com/tutorial/5409/en/#toc3
http://www.ni.com/example/6999/en/#C.NETandVisualBasic.NETVB.NET
Regards,
07-13-2016 11:24 AM
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
07-13-2016 12:02 PM
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.