NI產品與技術 討論區

取消
顯示結果 
搜尋替代 
您的意思是: 

新手 C寫出兩筆電壓訊號

工程師您好:

我目前使用的擷取卡是USB-6289 使用Microsoft Visual C ,我想要擷取兩筆電壓訊號,並且同時以txt檔方式寫入E槽 請問我該怎麼做?

以下是我目前的程式問題:

int32 CVICALLBACK EveryNCallback1(TaskHandle taskHandleTemperture, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData);
int32 CVICALLBACK DoneCallback1(TaskHandle taskHandleTemperture, int32 status, void *callbackData);

void main(){

DAQmxErrChk(DAQmxCreateTask("", &taskHandleTemperture));
DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandleTemperture, "Dev1/ai0:1", "Voltagemeasure,Temperturemeasure", DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandleTemperture, "", 1000.0, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1000));

 


fprintf(fp1, "Times(s) Temperture\n");
DAQmxErrChk(DAQmxRegisterEveryNSamplesEvent(taskHandleTemperture, DAQmx_Val_Acquired_Into_Buffer, 1000, 0, EveryNCallback1, NULL));
DAQmxErrChk(DAQmxRegisterDoneEvent(taskHandleTemperture, 0, DoneCallback1, NULL));

DAQmxErrChk(DAQmxStartTask(taskHandleTemperture));

printf("Acquiring samples continuously. Press Enter to interrupt\n");
getchar();


DAQmxStopTask(taskHandleTemperture);
DAQmxClearTask(taskHandleTemperture);

 

}

nt32 CVICALLBACK EveryNCallback1(TaskHandle taskHandleTemperture, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
{
int y = 0;
int32 error = 0;
char errBuff[2048] = { '\0' };
static int totalRead = 0;
int32 read = 0;
float64 data[1000];
float64 data1[1000];
static float k = 0;

 

/*********************************************/

// DAQmx Read Code
/*********************************************/
DAQmxErrChk(DAQmxReadAnalogF64(taskHandleTemperture, 1000, 10.0, DAQmx_Val_GroupByScanNumber, data, 1000, &read, NULL));
if (read>0) {
for (int i = 0; i < 999; i++) {
fprintf(fp1, "%0.3f +%0.4e\n", k, data[i]);
k = k + 0.001;
//fprintf(fpT, "+%0.4e\n", data[i]);
}
printf("Acquired %d samples. Total %d\r", (int)read, (int)(totalRead += read));
fflush(stdout);

}

 

0 積分
1 條訊息(共 1 條)
2,140 檢視