12-30-2013 08:43 PM - edited 12-30-2013 08:52 PM
I write a function to return a float64 type pointer and assign the pointer to my defined Pionter "newdata" in my StartCallBack,there's no error,but when I USE "
DAQmxWriteAnalogF64 (gtaskhandle0, leng[0]<=leng[1]?2*leng[0]:2*leng[1], 0, 10.0, DAQmx_Val_GroupByScanNumber, newdata, &written, NULL);",
I get a run-time-error like this : "work.c", line 231, col 121, thread id 0x00007FB4: Array argument too small (40000000 bytes). Argument must contain at least 80000000 bytes (10000000 elements).Why this happen?
My part code:
DAQmxCreateTask ("", >askhandle0);
DAQmxCreateAOVoltageChan (gtaskhandle0, "Dev1/ao0:1", "", -10.0, 10.0, DAQmx_Val_Volts, "");
DAQmxSetTimingAttribute(gtaskhandle0,DAQmx_SampClk_Rate,1000/looptime);
DAQmxCfgSampClkTiming(gtaskhandle0,"",1000/looptime,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,leng[0]+leng[1]);
DAQmxRegisterDoneEvent(gtaskhandle0,0,DoneCallback,NULL);
DAQmxWriteAnalogF64 (gtaskhandle0, leng[0]<=leng[1]?2*leng[0]:2*leng[1], 0, 10.0, DAQmx_Val_GroupByChannel, newdata, &written, NULL);
SetCtrlAttribute (panelHandle, PANEL_REALWRITE, ATTR_CTRL_VAL, (double)written);
DAQmxStartTask(gtaskhandle0);
Solved! Go to Solution.
12-31-2013 01:19 AM
I would assume that your array is too small - how do you allocate its memory? Does it allow for 10000000 float64 elements?
12-31-2013 01:48 AM
I do not think so ,when I modificate the channel from "Dev1/ao0:1" to "Dev1/ao0",it works normally ,but I can output only in one AO channel by this way ,rather than in two AO channels.
float64 * volarray(double ti[],double vi[],int num,int len,double looptime)
{
int k=0,sum=0,m=0;
float64 *p=NULL;
p=(float64 *) malloc(sizeof(double)*len);
for(k=0;k<num-1;)
{
if(ti[k]<ti[k+1])
{for(m=0;m<(int) (ti[k+1]-ti[k])/looptime;m++)
p[m+sum]= vi[k]+m*(vi[k+1]-vi[k])/((ti[k+1]-ti[k])/looptime);
sum+= (int) (ti[k+1]-ti[k])/looptime ;
k+=1;
}
else
{for(m=0;m<(int) (ti[k+2]-ti[k+1])/looptime;m++)
p[m+sum]= vi[k+1]+m*(vi[k+2]-vi[k+1])/((ti[k+2]-ti[k+1])/looptime);
sum+= (int) (ti[k+2]-ti[k+1])/looptime ;
k+=2;
}
}
return p;}
float64 * JointVol( float64 *data0, float64 *data1, int len0, int len1 )
{ int i=0;
int totalLen=0;
float64 * P=NULL;
if(len0<=len1)
totalLen=2*len0;
else
totalLen=2*len1;
//totalLen=((len0<=len1)?len0:len1)*2;
P=(float64*)malloc(sizeof(double)*totalLen);
for(i=0;i<(totalLen/2);++i)
{
P[2*i]=*(data0+i);
P[2*i+1]=*(data1+i);
}
return P;
}
12-31-2013 07:22 AM
From the code we cannot see how many samples do you expect to write but there are two aspects to consider.
DAQmxWriteAnalogF64 expects to receive the numer of samples per channel to write; that is, your "2*" in the function call is probably wrong. See here for the function help. This may cause the error you are receiving, as the array lenght does not match the settings (you probably want to write 5 million samples per channel).
Second aspect, it seems to me that your function is producing the final array with interleaved samples (that is, array1[0], array2[0], array1[1], array2[1].... array1[n-1], array2[n-1]). If this is true, you should pass DAQmx_Val_GroupByScanNumber in the function call.
12-31-2013 08:51 PM
I have solved it yesteday,and the code exists the same problems as you say .It is really grateful for your suggestion.
Best Wishes.