10-27-2006 08:12 AM
10-30-2006 12:31 PM
10-30-2006 11:55 PM
10-31-2006 04:13 AM
I have managed to remove the error by slightly modifying the code so that reading's dont go into the negative zone but even though the program works fine the output is not generated on the voltmeter.I know the problem is in the program bcoz the program in VB works fine.
here is my modified code please help.
----------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <math.h>
#include <NIDAQmx.h>
#if defined(WIN32) || defined(_WIN32)
#include <windows.h>
#endif
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
#define PI 3.1415926535
int main(void)
{
int error=0;
TaskHandle taskHandle=0;
float64 data[1000];
char errBuff[2048]={'\0'};
uInt32 i=0;
i = 0;
/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle,"Dev1/ao0","",0.000000,5.000000,DAQmx_Val_Volts,NULL));
/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk (DAQmxStartTask(taskHandle));
printf("Generating samples continuously. Press Ctrl+C to interrupt\n");
while( 1 ) {
#if defined(WIN32) || defined(_WIN32)
Sleep(1);
#else
#error - This example requires a platform specific sleep call.
/*********************************************/
// This example requires a platform specific sleep call.
// For example:
//
// #include <windows.h>
// Sleep(1); // For Windows platform
//
// #include <unistd.h>
// usleep(1000); // For Linux platform
/*********************************************/
#endif
for(;i<1000;i++)
{
data[i] = 5.0*sin((double)i*2.0*PI/1000.0);
if(data[i]<0)
data[i]*=-1;
printf("\ndata[%d]=%0.2f",i,data[i]);
DAQmxErrChk (DAQmxWriteAnalogScalarF64(taskHandle,1,-1,data[i],NULL));
if(i%1==0)
getch();
}
/*********************************************/
// DAQmx Write Code
/*********************************************/
//DAQmxErrChk (DAQmxWriteAnalogScalarF64(taskHandle,1,-1,data[i],NULL));
//if( ++i>=1000 )
// i = 0;
}
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);
printf("End of program, press Enter key to quit\n");
getchar();
return 0;
}
10-31-2006 06:49 AM
10-31-2006 10:19 AM