Before looking at the code, here's an explanation: NIDAQmx is a hardware-in-the-loop integration software from National Instruments. They give this sample code to create any voltage out of the card. The variable "float64 data[1]" is a double precision floating point that defines the actual voltage being emitted from the card; it is referenced later in the fourth line with function "DAQmxErrChk". However, despite my best efforts, I cannot seem to change that voltage. This is because it is in curly braces, which is a permanent array initialization. But, when I take the curly braces off or try to define data in another line of code, I get cross-type errors. The code is exclusive to DAQmx, so it may look confusing, but all I'm having problems with is data.
#include <stdio.h>
#include <NIDAQmx.h>
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else//if it finds an error, stop running.
int main()
{
int error=0;
TaskHandle taskHandle=0;
char errBuff[2048]={'\0'};//error message
float64 data[1] = {7.00};//problem variable
printf("%f\n",data[1]);//print it, which works
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));//create a task
DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle,"Dev1/ao0","",-10.0,10.0,DAQmx_Val_Volts,""));//assign the task a channel
DAQmxErrChk (DAQmxStartTask(taskHandle));//start the task
DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));//put voltage through the channel
Error:
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( taskHandle!=0 )
{
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}
if( DAQmxFailed(error) )
printf("DAQmx Error: %s\n",errBuff);//print the error message
printf("End of program, press Enter key to quit\n");
getchar();
return 0;
}