Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Checking for Buffer half-ready in analog output

Greetings,

In converting our Traditional DAQ-based code to be compliant with DAQmx, I notice that among the missing functions are WFM_DB_HalfReady and DAQ_DB_HalfReady, which we used to ensure that the buffer was ready for further reading/writing as the situation called for it.  With the new system, I do not how to tell the board (PCI-6052E) to wait until the buffer is ready for output; for example, I get the following error when I try to call DAQmxWriteAnalogF64 within a while-loop:

NON-FATAL RUN-TIME ERROR:
"edspatial.c", line 1493, col 25, thread id 0x00000EC0
 
Function DAQmxWriteAnalogF64: (return value == -200288 [0xfffcf1a0]).
Attempted to write a sample beyond the final sample generated. The generation has stopped, therefore the sample specified by the combination of position and offset will never be available.  

Specify a position and offset which selects a sample up to, but not beyond, the final sample generated. The final sample generated can be determined by querying the total samples generated after a generation has stopped.

Attempted to Write Sample: 16000 
Property: DAQmx_Write_RelativeTo
Corresponding Value: DAQmx_Val_CurrWritePos 
Property: DAQmx_Write_Offset
Corresponding Value:   

Task Name: _unnamedTask<1> 
Status Code: -200288

Any help in this situation would be most appreciative.  Thank you.

- Gilberto

0 Kudos
Message 1 of 6
(3,766 Views)

Hi Gilberto,

Here is a KB which talks about why you are getting the error -200288. The NI-DAQmx C Reference help may also be useful, and can be found under Start » Programs » National Instruments » NI-DAQ. This explains all of the DAQmx function calls and details about them. Some good examples can be found under C:\Program Files\National Instruments » MeasurementStudioVS2003 or 2005 depending on what you are programming with.

David L.
Systems Engineering
National Instruments
0 Kudos
Message 2 of 6
(3,746 Views)
Thanks for the link, it indeed helped.

Well, after much hemming and hawing, I was finally able to get the DAQmx version working like the Traditional DAQ version!

...for the most part.  There still seems to be a remnant of a timing issue, as I will explain in the code below (included for clarification):

/* Configure the Analog Input  */
char    trigName[256];
DAQmxErrChk (DAQmxCreateTask("",&inputTaskHandle));
DAQmxErrChk (DAQmxCreateAIVoltageChan(inputTaskHandle,"Dev1/ai0","",DAQmx_Val_NRSE,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCreateAIVoltageChan(inputTaskHandle,"Dev1/ai1","",DAQmx_Val_NRSE,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCreateAIVoltageChan(inputTaskHandle,"Dev1/ai7","",DAQmx_Val_NRSE,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming (inputTaskHandle, "", 32000.0, DAQmx_Val_Rising, DAQmx_Val_ContSamps, ulAOCount));
DAQmxErrChk (GetTerminalNameWithDevPrefix(inputTaskHandle,"ai/StartTrigger",trigName));
DAQmxErrChk (DAQmxCfgInputBuffer(inputTaskHandle,ulAOCount));
DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(inputTaskHandle,DAQmx_Val_Acquired_Into_Buffer,ulAOHalfCount,0,EveryNCallbackIn,NULL));

/* Configure the Analog Output */

DAQmxErrChk (DAQmxCreateTask("",&outputTaskHandle));
DAQmxErrChk (DAQmxCreateAOVoltageChan(outputTaskHandle,"Dev1/ao1","",-10.0,10.0,DAQmx_Val_Volts,NULL));
               
// Setup Synchronous DAQ
// Trigger analog output from the analog input
DAQmxErrChk (DAQmxCfgSampClkTiming (outputTaskHandle, "", 32000.0, DAQmx_Val_Rising, DAQmx_Val_ContSamps,ulAOCount));
DAQmxErrChk (DAQmxCfgOutputBuffer(outputTaskHandle,ulAOCount));
DAQmxErrChk (DAQmxSetWriteRegenMode(outputTaskHandle,DAQmx_Val_DoNotAllowRegen));
DAQmxErrChk (DAQmxSetDigEdgeStartTrigSrc(outputTaskHandle,trigName)); //Will this work?
DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(outputTaskHandle,DAQmx_Val_Transferred_From_Buffer,ulAOHalfCount,0,EveryNCallbackOut,NULL));
/* The callback function here tells the board what to load into the output buffer based on a counter within the callback */

The end result of the program should be that 1 s of zero-padded buffer is output, followed by a stimulus, then another second of zero-padded buffer; one of the input lines should read this back in and store it.  The problem, I believe, is in synchronization between the input and output; the record of the output collected from the appropriate input channel shows less than a second of zero-padded buffer, suggesting that the output is starting sooner than the input (when I checked the number of points written and read from the DAQmxWrite and DAQmxRead codes, respectively, the correct number of points was returned, suggesting that points were not dropped).  Any advice on this situation?

Thanks so much.
0 Kudos
Message 3 of 6
(3,745 Views)
Hi,
 
I am still looking into your code to see if I can find a good reason for this.  I will post back with my results. 
 
Ed W.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 6
(3,726 Views)

Hi,

 

How much less than 1 sec is the output buffer – how are you measuring this?  I haven’t found any glaring problems with your code, but you don’t have the callback functions showing.  This may be helpful for troubleshooting the program.  I would recommend stepping through the code to see when the callbacks are actually made.  Using this info and the number of input samples already acquired, you should be able to determine where and why the output is occurring ahead of schedule.

 

Ed W.

Applications Engineer

National Instruments

0 Kudos
Message 5 of 6
(3,711 Views)
Hi Gilberto,
 
In looking through your code, I believe you want to use the following function to setup up the start trigger for your analog output operation (explanation from DAQmx C reference help included):
 

DAQmxCfgDigEdgeStartTrig

int32 DAQmxCfgDigEdgeStartTrig (TaskHandle taskHandle, const char triggerSource[], int32 triggerEdge);

Purpose

Configures the task to start acquiring or generating samples on a rising or falling edge of a digital signal.

Parameters

Input
Name Type Description
taskHandle TaskHandle The task used in this function.
triggerSource const char [] The name of a terminal where there is a digital signal to use as the source of the trigger.
triggerEdge int32 Specifies on which edge of a digital signal to start acquiring or generating samples.
Value Description
DAQmx_Val_Rising Rising edge(s).
DAQmx_Val_Falling Falling edge(s).

Return Value

Name Type Description
status int32 The error code returned by the function in the event of an error or warning. A value of 0 indicates success. A positive value indicates a warning. A negative value indicates an error.
 
I *think* the DAQmxSetDigEdgeStartTrigSrc function you were using can be used to change the source of a start trigger once it has been configured (but I don't believe it will actually configure it), though I'd admit I'm not real certain after reading the help file.
 
Hope this helps,
Dan
 
0 Kudos
Message 6 of 6
(3,701 Views)