09-03-2018 12:50 AM
Using:
Visual Studio 2015
NI-Usb6289
problme:C2664 'int32 DAQmxReadAnalogF64(TaskHandle,int32,float64,bool32,float64 [],uInt32,int32 *,bool32 *)': cannot convert argument 5 from 'float64 [2][1000]' to 'float64 []' .
if I use this function
"DAQmxErrChk(DAQmxReadAnalogF64(taskHandleTemperture, 1000, 10.0, DAQmx_Val_GroupByChannel, data, 2000, &read, NULL));",
the rule just can put in the one-dimensional array (only temperature or voltage), how can I use this function to read temperature and voltage in the same time?
this my initial contact, thank you for your help
complete code:http://codepad.org/rNTt12V2
A partial code:
int32 CVICALLBACK EveryNCallback1(TaskHandle taskHandleTemperture, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
{
int32 error = 0, written, j = 0;
char errBuff[2048] = { '\0' };
static int totalRead = 0, flag = 1, flag1 = 1, flag2 = 1;
int32 read = 0;
float64 data[2][1000], tmp, tmpT, dataVout[4000];
static float k = 0;
static float64 foreverbig;
/*********************************************/
// DAQmx Read Code
/*********************************************/
DAQmxErrChk(DAQmxReadAnalogF64(taskHandleTemperture, 1000, 10.0, DAQmx_Val_GroupByChannel, data, 2000, &read, NULL));
if (read > 0) {
for (int i = 0; i < 999; i++) {
fprintf(fp, "%0.3f %+0.4e %f\n", k, data[0][i], transferVoltage(data[0][i])); //Temperature 1
fprintf(fp1, "%0.3f %+0.4e\n", k, data[1][i]); //Voltage
k = k + 0.001;
}
for (int m = 0; m < 998; m++) {
for (int n = 0; n < 998 - m; n++) {
if (data[0][n + 1] > data[0][n]) {
tmpT = data[0][n];
data[0][n] = data[0][n + 1];
data[0][n + 1] = tmpT;
}
}
}
10-13-2018 04:42 AM - edited 10-13-2018 04:42 AM
Syntactically a two dimensional array is not the same as a one dimensional array, eventhough for arrays that got declared with both dimensions with a fixed size the C compiler really creates a single memory buffer with x*y elements.
So maybe this did work in the past with older Visual Studio versions but it definitely doesn't in more modern versions thanks to implementing C11 and other modern standards more correctly.
The quick and dirty fix is to typecast your parameter when passing it to the function. Something like:
DAQmxErrChk(DAQmxReadAnalogF64(taskHandleTemperture, 1000, 10.0, DAQmx_Val_GroupByChannel, (float64*)data, 2000, &read, NULL));
should probably work.