07-19-2022 02:26 AM
Hello,
I'm using text based API and a NI 9201. I'm trying to get voltage samples. I found that the DAQmxReadAnalogF64() function always takes a lot of time. So I did a bit of research and decided to use function DAQmxSetAIADCTimingMode().
However, I don't know the name of the channel. The name of the chassis is "NI-DAQ". There are 4 C modules. The name of the physical channel for the measurement is "NI-DAQMod4/ai0".
I called function like this error |= DAQmxSetAIADCTimingMode(*task, "NI-DAQMod4\ai0", DAQmx_Val_HighSpeed);
But I the status bit returns an error. What is the correct channel name?
07-19-2022 08:40 PM
Just add more information, calling DAQmxSetAIADCTimingMode() with NI 9201, returns status -200458. It seems NI 9201 does not support this API. What are my options to improve execution time of DAQmxReadAnalogF64()?
07-19-2022 09:31 PM
It is difficult to help/guide without seeing what you've created and how instruments appear in your NI MAX. As a starting point, please share the code that you created and a snippet of how your C-series modules appear in NI MAX.
On the other hand, have you looked at the examples that ship with DAQmx drivers?
07-20-2022 12:06 AM
I'm on Linux, so I cannot use NI MAX.
Using command nilsdev, there is one NI DAQ chassis with 4 DAQmx C modules.
NI-DAQ
NI-DAQMod4
NI-DAQMod3
NI-DAQMod1
NI-DAQMod2
I'm using NI-DAQMod4, which is a NI 9201 to measure analog input of voltage.
The code is below:
error = DAQmxCreateTask("", task);
// value of 'chan' is "NI-DAQMod4/ai0".
error |= DAQmxCreateAIVoltageChan(*task, chan, "", DAQmx_Val_Cfg_Default, 0.0, 5.0, DAQmx_Val_Volts, NULL);
// value of 'buf' is "".
// value of 'KDAQNI::config.rate_ms' is 25.
error = DAQmxCfgSampClkTiming(*task, buf, (1000.0 / (float64)KDAQNI::config.rate_ms), DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1);
There is a thread running which read the analog input:
while (KDAQ_TASK_STATE_RUNNING == io->state)
{
result = DAQmxReadAnalogF64(io->task, 1, 0.025,
DAQmx_Val_GroupByChannel, values, 1, &samples, NULL);
// Handle errors
if (result < 0)
{
LOG_DEBUG(LOG_KDAQ, "AI failed read within 0.5s [result=%d]",
result);
}
else
{
for (i=0; i<num_io; i++)
{
*io->io[i].register_ptr = ((float64)io->io[i].scale_factor) *
(values[i] - (float64)io->io[i].offset);
}
}
}
DAQmxReadAnalogF64(io->task, 1, 0.025,
DAQmx_Val_GroupByChannel, values, 1, &samples, NULL) function takes long time to run, about 15 - 25 ms.
07-20-2022 10:51 PM
Update: I'm measuring a counter input and an analog input at the same time. Counter input is measured using a NI 9421. Analog input is measured using a NI 9201.
After some experiments, DAQmxReadAnalogF64() function is also interfering the counter input measurement.
Without DAQmxReadAnalogF64() function, counter input measurement is good and accurate.
But with DAQmxReadAnalogF64() function running in a thread every 25ms, counter input measurement is wrong and very inconsistent.
I understand that DAQmxReadAnalogF64() is a blocking function, but I do not expect it interfering with other measurements.