02-25-2013 02:41 PM
I'm trying to get analog input and output working at the same time, namely in MS Visual Studio with C++. Currently, I've run the Acq-IntClk analog input example, which works, but the voltages are off. However, the expected voltage drops are still present. When measuring zero voltage, the output has a tendency to drop ~.1V every two or three elements in the array. For example, when exposed to no voltage, data[0] will start at -5.9V, and then decrease to -6.0V at around data[2].
Now on to the actual issue:
#include <stdio.h>
#include <math.h>
#include "NIDAQmx.h"
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
int main(void)
{
int error=0;
TaskHandle taskHandle=0;
TaskHandle taskHandle2=0;
TaskHandle taskHandle3=0;
int32 read;
float64 data[4000];
float64 data2[100];
char errBuff[2048]={'\0'};
int i=0;
int32 written;
for(;i<4000;i++)
data[i] = 10.0*(double)i/4000.0;
/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateTask("",&taskHandle2));
DAQmxErrChk (DAQmxCreateTask("",&taskHandle3));
DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle,"Dev1/ao0","",-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",500,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,4000));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle2,"",10.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,100));
DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle2,"Dev1/ai0","",DAQmx_Val_Cfg_Default,0,8,DAQmx_Val_Volts,NULL));
/*********************************************/
// DAQmx Write Code
/*********************************************/
DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,4000,0,10.0,DAQmx_Val_GroupByChannel,data,&written,NULL));
/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk (DAQmxStartTask(taskHandle));
DAQmxErrChk (DAQmxStartTask(taskHandle2));
DAQmxErrChk (DAQmxReadAnalogF64(taskHandle2,100,10.0,DAQmx_Val_GroupByChannel,data2,100,&read,NULL));
/*********************************************/
// DAQmx Wait Code
/*********************************************/
DAQmxErrChk (DAQmxWaitUntilTaskDone(taskHandle,10.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;
}
This code just integrates my two working parts, the analog in and output, but when I run it, I get Error -200477.
Thanks in advance.