Hello. These are the user defined functions used in my program.
There is some misunderstating for my question.
My program is about outputing position data that varies real time by user command.
I think that continous generation example you suggested is not proper for my application if there are no functions related to fast regeneration of buffer.
If you know about this, please describe it in detail of how to use using mx functions.
By the way, as you mentioned, Configure_WriteDigPortExtClk, Write_DigPortExtClk, Start_DigPortExtClk and Wait_DigPortExtClk functions in the while loop makes noticeable delay. But if move port setup function out of the while loop and place the write, start and wait functions inside, some error messages is occured when writing new buffer on the card. The error message is as follows. How can i solve this?
DAQmx Error: Measurements: Attempted to write a sample beyond the final sample g
enerated. The generation has stopped, therefore the sample specified by the comb
ination 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: 2496
Property: DAQmx_Write_RelativeTo
Corresponding Value: DAQmx_Val_CurrWritePos
Property: DAQmx_Write_Offset
Corresponding Value:
Task Name: _unnamedTask<2>
Status Code: -200288
int32 Configure_WriteDigPortExtClk(const char chan[], const char clockSource[], float64 rate, TaskHandle *taskHandle, uInt32 *numChannels, uInt32 sampsPerChan)
{
int32 error=0;
/*********************************************************************
* 1. Create a task.
* 2. Create a Digital Output Channel.
* 3. Call the DAQmxCfgSampClkTiming function which sets the sample
* clock rate. Additionally, set the sample mode to Finite.
*********************************************************************/
DAQmxErrChk (DAQmxCreateTask("",taskHandle));
DAQmxErrChk (DAQmxCreateDOChan(*taskHandle,chan,"",DAQmx_Val_ChanForAllLines));
DAQmxErrChk (DAQmxCfgSampClkTiming(*taskHandle,clockSource,rate,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,sampsPerChan));
DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(*taskHandle, "/Dev1/PFI6",DAQmx_Val_Falling));
//DAQmxSetTrigAttribute (*taskHandle, DAQmx_StartTrig_Retriggerable, TRUE);
if( numChannels )
DAQmxErrChk (DAQmxGetTaskAttribute(*taskHandle,DAQmx_Task_NumChans,numChannels));
Error:
return error;
}
int32 Configure_ReadDigPortExtClk(const char chan[], const char clockSource[], float64 rate, TaskHandle *taskHandle, uInt32 *numChannels, uInt32 sampsPerChan)
{
int32 error=0;
/*********************************************************************
* 1. Create a task.
* 2. Create a Digital Input Channel.
* 3. Call the DAQmxCfgSampClkTiming function which sets the sample
* clock rate. Additionally, set the sample mode to Finite.
*********************************************************************/
DAQmxErrChk (DAQmxCreateTask("",taskHandle));
DAQmxErrChk (DAQmxCreateDIChan(*taskHandle,chan,"",DAQmx_Val_ChanForAllLines));
DAQmxErrChk (DAQmxCfgSampClkTiming(*taskHandle,clockSource,rate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,sampsPerChan));
DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(*taskHandle, "/Dev1/PFI7",DAQmx_Val_Falling));
if( numChannels )
DAQmxErrChk (DAQmxGetTaskAttribute(*taskHandle,DAQmx_Task_NumChans,numChannels));
Error:
return error;
}
int32 Start_DigPortExtClk(TaskHandle taskHandle)
{
/*********************************************************************
* 3. Call the Start function to start the task.
*********************************************************************/
return DAQmxStartTask(taskHandle);
}
int32 Write_DigPortExtClk(TaskHandle taskHandle, uInt16 data[], uInt32 sampsPerChan)
{
/*********************************************************************
* 4. Write the waveform to the output buffer.
*********************************************************************/
return DAQmxWriteDigitalU16(taskHandle,sampsPerChan,0,5.0,DAQmx_Val_GroupByChannel,data,NULL,NULL);
}
int32 Read_Cont_DigPortExtClk(TaskHandle taskHandle, uInt16 *data, uInt32 bufferSize, int32 *read)
{
/*********************************************************************
* 4. Write the waveform to the output buffer.
*********************************************************************/
return DAQmxReadDigitalU16(taskHandle,bufferSize,10.0,DAQmx_Val_GroupByScanNumber,data,bufferSize,read,NULL);
}
int32 Wait_DigPortExtClk(TaskHandle taskHandle)
{
return DAQmxWaitUntilTaskDone(taskHandle,10.0);
}
int32 Stop_DigPortExtClk(TaskHandle taskHandle)
{
int32 error = 0;
/*********************************************************************
* 5. Call the Clear Task function to clear the Task.
*********************************************************************/
error = DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
return error;
}