1、使用NI MAX创建多路输入的测量任务
本处设置Dev1/ai0:3四路电压输入,采样率均为100,差分连接。
2、代码
// 设置地址
void Widget::on_add_pushButton_clicked()
{
address_txt = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
"/home",
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
ui->begin_pushButton->setEnabled(true);
ui->add_pushButton->setEnabled(false);
//操作记录
QString current_date = ui->textEdit->toPlainText();
QDateTime current_date_time =QDateTime::currentDateTime(); //获取当前时间
current_date +=current_date_time.toString("hh:mm:ss");
current_date += (address_txt);
current_date += "\n";
ui->textEdit->setText(current_date);
}
// 开始采集
void Widget::on_begin_pushButton_clicked()
{
//创建文本文档
QDateTime current_date_time =QDateTime::currentDateTime(); //获取当前时间
QString thename = current_date_time.toString("yyyy-MM-dd-hh-mm-ss");
fileName = thename+".txt";
fileName = address_txt+"/"+fileName;
file.setFileName(fileName);
file.open(QFile::WriteOnly);
//开始采集数据
int32 error = 0;
char errBuff[2048] = {
'\0' };
error += DAQmxCreateTask("",&taskHandle);
error += DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai0:3", "", DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL);
error += DAQmxCfgSampClkTiming(taskHandle, "", rate, DAQmx_Val_Rising, DAQmx_Val_ContSamps, sample);
error += DAQmxSetAITermCfg(taskHandle,"Dev1/ai0:3",DAQmx_Val_Diff);
error += DAQmxRegisterEveryNSamplesEvent(taskHandle, DAQmx_Val_Acquired_Into_Buffer, sample, 0,
EveryNCallback, (void*)this);
error += DAQmxRegisterDoneEvent(taskHandle, 0, DoneCallback, NULL);
error += DAQmxStartTask(taskHandle