Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DO task times out on second try, even after DAQmxBaseClearTask

Here is another problem (NI-DAQmxBase 2.1 on Mac OS X 14.4.11, M6251 card): I create an externally clocked DO task, stop it, clear it and try to do it again. On the 2nd attempt, writing samples to the DO buffer consistently times out. So I can only execute a DO task once: not very useful. Here is an excerpt of my code:

ctr0 is configured to output a 1 MHz clock which is manually wired to PFI0, this works so I will omit for clarity:

DAQmxErrChk (DAQmxBaseCreateTask("dummyDO",&taskHandleDO));
DAQmxErrChk (DAQmxBaseCreateDOChan(taskHandleDO, "Dev1/port0/line0", NULL, DAQmx_Val_ChanForAllLines));
#define dummySampleRate 1000
#define dummyNumSamples 1000
DAQmxErrChk (DAQmxBaseCfgSampClkTiming(taskHandleDO, "/Dev1/PFI0", dummySampleRate, DAQmx_Val_Rising, DAQmx_Val_ContSamps, dummyNumSamples)); // does not accept DAQmx_Val_FiniteSamps

#define FIFOmax 2047
// write the first chunk of samples to DO buffer, dataDO_32bit contains an arbitrary pulse pattern
DAQmxErrChk (DAQmxBaseWriteDigitalU32(taskHandleDO, FIFOmax, noAutoStart, kTimeOut, DAQmx_Val_GroupByChannel, dataDO_32bit, NULL, NULL));

DAQmxErrChk (DAQmxBaseStartTask(taskHandleDO));
// start the ctr0 task: this will clock the DO samples out
DAQmxErrChk (DAQmxBaseStartTask(taskHandleC0));

// write the final zero buffer to the FIFO, this stops the pulse generation; dataDOzero_32bit contains all 0's ***
DAQmxErrChk (DAQmxBaseWriteDigitalU32(taskHandleDO, FIFOmax, noAutoStart, kTimeOut, DAQmx_Val_GroupByChannel, dataDOzero_32bit, NULL, NULL));

// do it again just to see if we can write to buffer again w/o timeout: yes we can ***
DAQmxErrChk (DAQmxBaseWriteDigitalU32(taskHandleDO, FIFOmax, noAutoStart, kTimeOut, DAQmx_Val_GroupByChannel, dataDOzero_32bit, NULL, NULL));

// now try the above again with a new DO task:
DAQmxBaseStopTask(taskHandleDO); // stop the first DO task
DAQmxBaseStopTask(taskHandleC0); // stop the clock too
DAQmxBaseClearTask(taskHandleDO); // clear the task so we can start over

// recreate an identical task to above
DAQmxErrChk (DAQmxBaseCreateTask("dummyDO",&taskHandleDO));
DAQmxErrChk (DAQmxBaseCreateDOChan(taskHandleDO, "Dev1/port0/line0", NULL, DAQmx_Val_ChanForAllLines));
DAQmxErrChk (DAQmxBaseCfgSampClkTiming(taskHandleDO, "/Dev1/PFI0, dummySampleRate, DAQmx_Val_Rising, DAQmx_Val_ContSamps, dummyNumSamples));

// write the first chunk of samples to DO buffer as before:
DAQmxErrChk (DAQmxBaseWriteDigitalU32(taskHandleDO, FIFOmax, noAutoStart, kTimeOut, DAQmx_Val_GroupByChannel, dataDO_32bit, NULL, NULL));

THIS LAST CALL TIMES OUT AND FAILS. WHY?

Why is it that I can write to the running DO task as many times as I want above (see commented lines with ***), yet I cannot perform a 2nd identical DO task with a brand new taskHandleDO?

How do you get around this one now?

Peter.
0 Kudos
Message 1 of 6
(3,641 Views)
Peter,

Finite correlated digital output operations are not supported under NI-DAQmx Base. This is why you are receiving the error. You must use DAQmx_Val_ContSamps.

Here are a few things I would suggest to do to try and debug your code. Hopefully these can help us narrow down the problem:

1) Try not stopping the counter task. This somehow could be affecting the sample clock for the second DO task.

2) Try creating the first and second DO tasks with different names.

3) Why are you clearing the task? It is not necessary to recreate an identical task. You can simply stop the first task, write to the buffer, and then start the task again.

Also, can you provide more details on what errors you are seeing? Please include the error codes as well.

You may also want to have a look at the DAQmx Base examples located at /Applications/National Instruments/NI-DAQmx Base/examples on a Mac.


Message Edited by Chris_D on 01-14-2008 09:24 PM
Regards,

Chris Delvizis
National Instruments
0 Kudos
Message 2 of 6
(3,582 Views)
Chris, partial reply:

>>> Finite correlated digital output operations are not supported under NI-DAQmx Base. This is why you are receiving the error. You must use DAQmx_Val_ContSamps.

I do use contSamples, see my code again.


>>> Try not stopping the counter task. This somehow could be affecting the sample clock for the second DO task

I can try and it may work, but this is not useful because I need to stop pulse generation between invocations of this code block. I can tell you tho that stepping thru these lines in the Xcode debugger (and therefore allowing lots of extra time for the clock to clock out the FIFO) still results in the same error on the 2nd try, so there is no way the FIFO wasn't cleared during a manual debug, if that's what you were getting at.


>>> Try creating the first and second DO tasks with different names.

The only reason I use a name is because of your memory leak caution in your ReadMe file. I'll try this, but it would mean I'd have to make up a new name for each invocation. Why would base have any recollection of the previous name if a taskClear was called?


>>> Why are you clearing the task? It is not necessary to recreate an identical task. You can simply stop the first task, write to the buffer, and then start the task again.

Because once i stop the task, restarting it causes a timeout, so I tried to kill the taskhandle completely with a Clear, but still there is persistence (I can only assume on the board somewhere, because the handle should be released and deleted completely?)


>>> You may also want to have a look at the DAQmx Base examples located at /Applications/National Instruments/NI-DAQmx Base/examples

That's what I based all my code on. I point out that some of those examples don't work even out of the box, see my previous posts.

I'm out of town for the week, I'll try this on the w/end and let you know more details.

P.
0 Kudos
Message 3 of 6
(3,575 Views)
Please try my suggestions when you get a chance. I am interested to see the results. In the mean time, I will work on setting up a system and try and reproduce your issues on my end. I have seen your other posts and I can assure you that other Applications Engineers are working on your issues and we will do our best to find their solutions.
Regards,

Chris Delvizis
National Instruments
0 Kudos
Message 4 of 6
(3,549 Views)
Hi Chris:

I had a chance to test your suggestions further:

>>> 2) Try creating the first and second DO tasks with different names.

Tried this, same error -200284 as before on the 2nd call to DAQmxBaseWriteDigitalU32

>>> 3) Why are you clearing the task? It is not necessary to recreate an identical task. You can simply stop the first task, write to the buffer, and then start the task again.

Tried this (stop the task w/o clearing), same error -200284 as before on the 2nd call to DAQmxBaseWriteDigitalU32

ctr0 was of course stopped, which it has to be, else spurious pulses would continue to be generated at the wrong times while the DO port is being set up (which excludes your suggestion #1).

I'll be working off-list with Ana P. to try to find some solutions.

Peter.
0 Kudos
Message 5 of 6
(3,520 Views)
Peter,

I do think its best that we take this issue offline for now. I have already been coordinating with Ana about replicating your setup and solving your issues. Please direct any further questions to her.
Regards,

Chris Delvizis
National Instruments
0 Kudos
Message 6 of 6
(3,510 Views)