本人刚刚接触NI板卡,有一个问题想请教大家。非常感谢。
我想要实现:每次在外部脉冲的触发下采集开始,每次采集5个点,下次采集开始也需要外部触发才开始,一共采集两次。但我现在的结果是一共采集10个点了,仅仅份两次读取而已。
请大神帮忙!感激涕零。下方是我写的部分代码。
DAQmxErrChk(DAQmxCreateTask("", &taskHandle1));
DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle1, "Dev1/ai4", "", DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL));
DAQmxErrChk(DAQmxCfgSampClktiming(taskHandle1, "", 10000, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 10));
DAQmxErrChk(DAQmxCfgDigEdgeStartTrig(taskHandle1, "/Dev1/PFI8", DAQmx_Val_Rising));
DAQmxErrChk(DAQmxStartTask(taskHandle1));
for (int j = 0; j != 2; ++j)
{
DAQmxErrChk(DAQmxReadAnalogF64(taskHandle1, 5, 10.0, 0, data,10, &read, NULL));
printf("Acquired %d points
", (int)read);
for (int i = 0; i != read; ++i)
{
printf("%f
", data);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
但是这样每次采集5个点,就需要每次开、关任务。
之前试过的程序如下,但是按照我的程序采集的信息是正确的,但是所耗时间太久。请问有没有什么好的办法?
int32 read;
int error = 0;
TaskHandle taskHandle1 = 0;
char errBuff[2048] = { ' ' };
float64 data[1000];
double sum = 0;
//Ai输入采集
DAQmxErrChk(DAQmxCreateTask("", &taskHandle1));
DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle1, "Dev1/ai4", "", DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle1, "", 10000, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps,5));
DAQmxErrChk(DAQmxCfgDigEdgeStartTrig(taskHandle1, "/Dev1/PFI8", DAQmx_Val_Rising));
for (int j = 0; j != 2; ++j)
{
DAQmxErrChk(DAQmxStartTask(taskHandle1));
DAQmxErrChk(DAQmxReadAnalogF64(taskHandle1, 5, 10.0, 0, data,10, &read, NULL));
printf("Acquired %d points ", (int)read);
for (int i = 0; i != read; ++i)
{
sum += data;
printf("%f ", data);
}
if (taskHandle1 != 0)
DAQmxStopTask(taskHandle1);
}
但是这样每次采集5个点,就需要每次开、关任务。
之前试过的程序如下,但是按照我的程序采集的信息是正确的,但是所耗时间太久。请问有没有什么好的办法?
int32 read;
int error = 0;
TaskHandle taskHandle1 = 0;
char errBuff[2048] = { ' ' };
float64 data[1000];
double sum = 0;
//Ai输入采集
DAQmxErrChk(DAQmxCreateTask("", &taskHandle1));
DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle1, "Dev1/ai4", "", DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle1, "", 10000, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps,5));
DAQmxErrChk(DAQmxCfgDigEdgeStartTrig(taskHandle1, "/Dev1/PFI8", DAQmx_Val_Rising));
for (int j = 0; j != 2; ++j)
{
DAQmxErrChk(DAQmxStartTask(taskHandle1));
DAQmxErrChk(DAQmxReadAnalogF64(taskHandle1, 5, 10.0, 0, data,10, &read, NULL));
printf("Acquired %d points ", (int)read);
for (int i = 0; i != read; ++i)
{
sum += data;
printf("%f ", data);
}
if (taskHandle1 != 0)
DAQmxStopTask(taskHandle1);
}
但是这样每次采集5个点,就需要每次开、关任务。
之前试过的程序如下,但是按照我的程序采集的信息是正确的,但是所耗时间太久。请问有没有什么好的办法?
int32 read;
int error = 0;
TaskHandle taskHandle1 = 0;
char errBuff[2048] = { ' ' };
float64 data[1000];
double sum = 0;
//Ai输入采集
DAQmxErrChk(DAQmxCreateTask("", &taskHandle1));
DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle1, "Dev1/ai4", "", DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle1, "", 10000, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps,5));
DAQmxErrChk(DAQmxCfgDigEdgeStartTrig(taskHandle1, "/Dev1/PFI8", DAQmx_Val_Rising));
for (int j = 0; j != 2; ++j)
{
DAQmxErrChk(DAQmxStartTask(taskHandle1));
DAQmxErrChk(DAQmxReadAnalogF64(taskHandle1, 5, 10.0, 0, data,10, &read, NULL));
printf("Acquired %d points ", (int)read);
for (int i = 0; i != read; ++i)
{
sum += data;
printf("%f ", data);
}
if (taskHandle1 != 0)
DAQmxStopTask(taskHandle1);
}
但是这样每次采集5个点,就需要每次开、关任务。
之前试过的程序如下,但是按照我的程序采集的信息是正确的,但是所耗时间太久。请问有没有什么好的办法?
int32 read;
int error = 0;
TaskHandle taskHandle1 = 0;
char errBuff[2048] = { ' ' };
float64 data[1000];
double sum = 0;
//Ai输入采集
DAQmxErrChk(DAQmxCreateTask("", &taskHandle1));
DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle1, "Dev1/ai4", "", DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle1, "", 10000, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps,5));
DAQmxErrChk(DAQmxCfgDigEdgeStartTrig(taskHandle1, "/Dev1/PFI8", DAQmx_Val_Rising));
for (int j = 0; j != 2; ++j)
{
DAQmxErrChk(DAQmxStartTask(taskHandle1));
DAQmxErrChk(DAQmxReadAnalogF64(taskHandle1, 5, 10.0, 0, data,10, &read, NULL));
printf("Acquired %d points ", (int)read);
for (int i = 0; i != read; ++i)
{
sum += data;
printf("%f ", data);
}
if (taskHandle1 != 0)
DAQmxStopTask(taskHandle1);
}
一周热门 更多>