Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with simultaneous AnalogOut + DigitalOut

Hi,
 
I am trying to output a stream of AnalogOutput and DigitalOutput in C++ Builder.  An earlier version of the program without the digital output could successfully stream out AnalogOutput.  However when the DigitalOutput was added (see below) I got:
    DAQmx Error:The transfer within the timeout period or within the specified number of retries.
    Task Name: _unnamedTask<1>
    Status Code: -50400
 
The error occurred when I tried to start the DigitalOutput task.
 
The essential code is here:
 
 
 // DAQmx Configure Code
 DAQmxErrChk (DAQmxCreateTask("", &hAOtask));
 DAQmxErrChk (DAQmxCreateAOVoltageChan(hAOtask, "Dev3/ao0", "", -10.0, 10.0, DAQmx_Val_Volts, NULL));
 DAQmxErrChk (DAQmxCfgSampClkTiming(hAOtask, "OnboardClock", 1000.0, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1000));
 
  DAQmxErrChk (DAQmxCreateTask("", &hDOtask));
 DAQmxErrChk (DAQmxCreateDOChan(hDOtask, "Dev3/port0", "", DAQmx_Val_ChanForAllLines));
 DAQmxErrChk (DAQmxCfgSampClkTiming(hDOtask,
                                       "/Dev3/ao/SampleClock",                                              //"Dev3/ao/SampleClock",       // Got DAQmx Error if used this: "Source terminal to be routed could not be found on the device."
                                       1000.0, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1000));
 
// DAQmx Prevent Regeneration
DAQmxErrChk (DAQmxSetWriteRegenMode(hAOtask, DAQmx_Val_DoNotAllowRegen));
DAQmxErrChk (DAQmxSetWriteRegenMode(hDOtask, DAQmx_Val_DoNotAllowRegen));
 
// DAQmx Write Code
DAQmxErrChk (DAQmxWriteAnalogF64(hAOtask, 1000, 0, 10.0, DAQmx_Val_GroupByChannel, AObuffer, &NumAOsamplesWritten, NULL));
DAQmxErrChk (DAQmxWriteDigitalU32(hDOtask, 1000, 0, 10.0,
                                      DAQmx_Val_GroupByChannel,
                                      DObuffer, &NumDOsamplesWritten, NULL));
// DAQmx Start Code
DAQmxErrChk (DAQmxStartTask(hAOtask));
DAQmxErrChk (DAQmxStartTask(hDOtask));                          // <===== GOT ERROR HERE -50400, DAQmxErrorPALTransferTimedOut
 
 
There are quite a few examples of continuous AnalogOutput + DigitalOutput in Labview and C#, but I haven't found one in ANSI C.  Can anyone tell me what I am doing wrong (I am quite new to DAQmx).
 
I use the PCI-6221 AD board, Windows XP and C++ Builder (but if you remove the line #pragma link "nidaqmx.lib", it should compile in Visual C++).
 
Thank you
 
0 Kudos
Message 1 of 4
(3,323 Views)

Hi Bill

 

Here are a bunch of ANSI C DAQmx examples that are shipped with NI DAQ

 

C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C

Here is a link for some more examples

DAQmx - Write Digital Channel with Digital Start Trig - LabVIEW - CVI - VB.NET - ANSI C - C#

http://venus.ni.com/stage/utf8/niepd_web_display.DISPLAY_EPD4?p_answer=&p_guid=F0F6166C04697184E0340003BA7CCD71&p_node=201181&p_rank=&p_source=Internal&p_submitted=N

This is more specific for your board this is a Microsoft Visual C++ project but the code should still work  

Digital Read and Write Using Two Digital Ports

http://venus.ni.com/stage/utf8/niepd_web_display.DISPLAY_EPD4?p_answer=&p_guid=F1AFBB03CCE70E5CE0340003BA7CCD71&p_node=201196&p_rank=&p_source=Internal&p_submitted=N

 

A bit of information about the error -50400 occurred at DAQmx Start Task.vi.

 

By default, on-board regeneration is enabled on M-Series DAQ devices. This means that a continuous output task will repeatedly output the data in its buffer. If this data is updated with a write, the output will eventually change, but there is no guarantee on when this change will occur. Setting the DAQmx Write RegenMode property to "Do Not Allow Regeneration" specifies that data should be output only once and that new data should be written to the buffer before the output pointer reaches that location in the buffer a second time. This is useful for continuous digital pattern output.

The one caveat to this process is that the output buffer must be at least as large as the physical memory on the card. For M-Series devices, the DIO FIFO size is 2046 samples. If the buffer size is smaller than this, error 50400 is generated at DAQmx Start task, with description, "The transfer did not complete within the timeout period or within the specified number of retries."

 

Hope this helps

 

Tim

0 Kudos
Message 2 of 4
(3,284 Views)
Thanks Tim,
 
You are a genius!  I could have been staring at my code for days and never come up with this solution.
 
Your suggestion:
"The one caveat to this process is that the output buffer must be at least as large as the physical memory on the card. For M-Series devices, the DIO FIFO size is 2046 samples. If the buffer size is smaller than this, error 50400 is generated at DAQmx Start task, with description, "The transfer did not complete within the timeout period or within the specified number of retries." "
 
was the solution.  My DigitalOut buffer size was 1000, lower than the required 2047 or more.  When I increased it to 10000, everything worked fine.
 
The final working code in C is included in the attachment.
0 Kudos
Message 3 of 4
(3,281 Views)

Cool glad you are sorted thanks for the code.

 

Tim

 

AE NI UK and Ireland

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