04-18-2012 07:34 AM
Almighty gurus,
I'm total beginner in the NI-world, so sorry if I'm forgetting something obvious.
my environment: USB-9423, WinXP SP3, MS Visual Studio 2008
My problem is fairly simple: at raising edge of line0 I want to read status of line1. I copied the ANSI-C example "ContReadDigChan-ExtClk.c" and tried to modify parameters to achieve my goal. I'm not able to force my program to read just one sample at the raising-edge of line0, apparently I'm receiving intermittent numbers of samples. What I'm doing wrong? Many thanks for any helpful hints...
Petr
Here is my main()
int main(int argc, char *argv)
{
int32 error=0;
TaskHandle taskHandle=0;
uInt8 data[1];
int32 sampsRead,totalRead=0;
char errBuff[2048]={'\0'};
/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateDIChan(taskHandle,"CDAQ1Mod1/port0/line1","",DAQmx_Val_ChanPerLine));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"/CDAQ1Mod1/PFI0",1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1));
/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk (DAQmxStartTask(taskHandle));
printf("Acquiring samples continuously. Press Ctrl+C to interrupt\n");
while( 1 ) {
/*********************************************/
// DAQmx Read Code
/*********************************************/
DAQmxErrChk (DAQmxReadDigitalU8(taskHandle,1,10.0,DAQmx_Val_GroupByChannel,data,1,&sampsRead,NULL));
if( sampsRead>0 ) {
totalRead++;;
printf("Acquired %d samples (%i)\n", totalRead, data[0]);
fflush(stdout);
}
}
Error:
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( taskHandle!=0 ) {
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}
if( DAQmxFailed(error) )
printf("DAQmx Error: %s\n",errBuff);
return 0;
}