Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxIsTaskDone never finishes

Hi all!
 
I'm using NI PCI 6221 under C# as I created a dll from NIDAQmx.lib, that's why those 'fn***' are written at the beginnings..
Now I've got some troubles with this code below:
 

IntPtr

writeAO, AOTaskHandle;
int kesz=0;
IntPtr done;

fnDAQmxCreateTask(

"Output", out AOTaskHandle);
fnDAQmxCreateAOVoltageChan(AOTaskHandle,
"Dev1/ao0", "Feszki", -10, 10, DAQmx_Val_Volts, null);
fnDAQmxCfgSampClkTiming(AOTaskHandle,
"", 20000, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 200000);
//AOdata containes the 200000 samples to put out

fnDAQmxWriteAnalogF64(AOTaskHandle, Convert.ToInt32(200000), 0, -1, DAQmx_Val_GroupByScanNumber, AOdata, out writeAO, (IntPtr)null);
fnDAQmxStartTask(AOTaskHandle);

while (kesz==0)
{
fnDAQmxIsTaskDone(AOTaskHandle,
out done);
kesz = done.ToInt32();
if (kesz==0) Thread.Sleep(1000);
}

The problem is that 'done' always keeps '0'. Why? Shouldnt it be a sign of the end of DAQmxWriteAnalogF64? (As I've found out, DAQmxWriteAnalogF64 only writes to the memory not directly to the line, that's why I put the fnDAQmxWriteAnalogF64 before the fnDAQmxStartTask. But reverse, there had been another problem: the running time of fnDAQmxWriteAnalogF64 was always about 140 miliseconds irrespectively of fnDAQmxCfgSampClkTiming... although it should have been exactly 10000 milisecs of course..)

Thanks ever so much for your answer!

0 Kudos
Message 1 of 5
(3,219 Views)
hello tarpista,

i tried to reproduce the behaviour. i used C to make the calls into the DAQ-DLL you make in C#.

on my system the DAQmxIsTaskDone returns true as soon as all samples are generated. so i cannot reproduce the behaviour you see on your system.

basically this function should return true if the task is done.

regards,

robert h
NI germany
0 Kudos
Message 2 of 5
(3,202 Views)
Hello TarPista,

If you check the error code returned by each DAQmx ANSI C function, it will give you a clearer idea of why your application is not working as expected.

Note that DAQmxCreateTask doesn't modify the value of the task handle pointer, but rather that of the integer that it points to. I am not a .NET expert, but I would expect that you could declare AOTaskHandle as an int instead of an IntPtr, and the nature of it being an out parameter would cause the compiler to pass a pointer to AOTaskHandle into DAQmxCreateTask. It may happen to work anyway if the task handle is being written to the IntPtr itself and the IntPtr is being converted into an integer when you call the other functions.

Also, you're correct that DAQmxWriteAnalogF64 only writes data to the buffer in memory (for hardware timed tasks). The data isn't actually output until you start the task. So the write function shouldn't take 10 seconds to run.

You will probably be better off using the DAQmx .NET API for your C# application, unless you have a specific reason to make a marshalling wrapper for the DAQmx ANSI C API. There is some information about the .NET API in these knowledge bases:
http://digital.ni.com/public.nsf/allkb/0ea34d565632dfe186256e7b00762dcc
http://digital.ni.com/public.nsf/websearch/F0FD13D2DD0C433986256D9C00468D29?OpenDocument
---
Brad Keryan
NI R&D
0 Kudos
Message 3 of 5
(3,194 Views)
TarPista,
 
If you look at your call to DAQmxCfgSampClkTiming, I noticed that you have set mode to DAQmx_Val_ContSamps.  This will set up your AO task as a continuous generation, or rather one which doesn't stop until you call DAQmx stop task (or the task errors).  Since you did not disallow buffer regeneration, I would expect that the 200,000 samples you wrote to be regenerated over and over.  As such, I would not expect that the task would be done unless your task had errored.  If your intention is only to write 200,000 samples, change your call to DAQmxCfgSampClkTiming to set the mode to finite (DAQmx_Val_FiniteSamps or something like this).  Configured in finite mode, I would expect DAQmxIsTaskDone to return true 10 seconds after you call Start Task.
 
Hope this helps,
Dan
Message 4 of 5
(3,191 Views)
Oh yess!!!!!Smiley Happy That was the problem!! Thank you very-very much and for your eagle-eyes!Smiley Very Happy
0 Kudos
Message 5 of 5
(3,171 Views)