这是我写的发送程序,波形数据由callbackData传过来。由于在计算rate的时候都是用的100hz,所以最后示波器量到的波形的频率也都是一样的100hz。可是我们项目的要求应该是不同的啊,请教高手解答。谢谢!
int CVICALLBACK thread_generate_wavedata (void *callbackData)
{
TaskHandle send_taskHandle = 0;
double rate, frequency;
bool32 done = 0;
uInt32 bufferSize;
int32 written, error = 0;
float64 *data = NULL;
char errBuff[2048] = {'\0'};
bufferSize = SAMPLES_PER_CYCLE * CYCLES_PER_BUFFER;
if( (data = malloc (bufferSize * sizeof(float64))) == NULL)
{
MessagePopup ("Error", "Not enough memory");
goto Error;
}
Copy1D (callbackData, bufferSize, data);
frequency = 100.0;
rate = (frequency * bufferSize) / CYCLES_PER_BUFFER;
DAQmxErrChk (DAQmxCreateTask("", &send_taskHandle));//D/A6 6259_C_AO0 D/A7 6259_C_AO1 D/A8 6259_C_AO2
DAQmxErrChk (DAQmxCreateAOVoltageChan(send_taskHandle, "Dev1/ao0,Dev1/ao1,Dev1/ao2", "", -10.0, 10.0, DAQmx_Val_Volts, NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(send_taskHandle, "", rate, DAQmx_Val_Rising, DAQmx_Val_ContSamps, SAMPLES_PER_CYCLE));
DAQmxErrChk (DAQmxWriteAnalogF64(send_taskHandle, SAMPLES_PER_CYCLE, 0, 10.0, DAQmx_Val_GroupByChannel, data, &written, NULL));
DAQmxErrChk (DAQmxStartTask(send_taskHandle));
ProcessDrawEvents();
b01_zong_aoRunning = 1;
while(b01_zong_aoRunning)
{
Sleep(100);
DAQmxErrChk (DAQmxIsTaskDone (send_taskHandle, &done));
if(done)
b01_zong_aoRunning = 0;
else
ProcessSystemEvents();
}
Error:
if(DAQmxFailed(error))
DAQmxGetExtendedErrorInfo(errBuff, 2048);
if( send_taskHandle != 0 )
{
DAQmxStopTask(send_taskHandle);
DAQmxClearTask(send_taskHandle);
}
if(data)
{
free (data);
data = NULL;
}
if(DAQmxFailed(error))
MessagePopup("DAQmx Error", errBuff);
return 1;
}