03-19-2012 07:37 PM
Hi everyone - I am using NIDAQ-mx with C++ and a NI USB-6341. I am looking to use a lowpass filter on the analog ins but don't know if this is possible.
The problem is this code gets hung up when I try to use the filter.
This is what I'm doing:
if( !( retVal = DAQmxCreateTask( "", &config->taskHandle ) ))
if( !( retVal = DAQmxCreateAIVoltageChan( config->taskHandle, ss.str(), "", DAQmx_Val_RSE,
config->minVoltage, config->maxVoltage, DAQmx_Val_Volts, NULL ) ) )
if( !( retVal = DAQmxSetAILowpassEnable(config->taskHandle, "", 1) ) )
if( !( retVal = DAQmxSetAILowpassCutoffFreq(config->taskHandle, ss.str(), 500) ) )
if( !( retVal = DAQmxCfgSampClkTiming( config->taskHandle, NULL, config->frequency,
DAQmx_Val_Rising, DAQmx_Val_ContSamps, numSamplesPerChannel ) ) )
Is this the correct way to do this. Do I create the task, then the AIchannel, then the filter, then the cutoff freq, then the timing?
Any help would be much appreciated.
Thanks!
Solved! Go to Solution.
03-20-2012 05:20 PM
Hi C2PO,
It seems you are doing things in the correct order (specifically addressing your final question of the post).
There are many examples that I hope were installed on your computer when you instaleld NI-DAQmx. These would be located under the Start Menu in Windows > All Programs > National Instruments | NI-DAQ > Text-Based Code Support > ANSI-C Examples. Here, one that I thought applied particularly well to your situation was in \NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage\Cont Acq -Int Clk-Cfg Filt-SCXI 114x
The applicable code here looks like:
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
DAQmxErrChk (DAQmxSetAILowpassEnable(taskHandle,"",1));
DAQmxErrChk (DAQmxSetAILowpassCutoffFreq(taskHandle,"",cutoffFreq));
DAQmxErrChk (DAQmxGetAILowpassCutoffFreq(taskHandle,"",&cutoffFreq));
Note: If these examples have not been installed on your computer, doing a repair of your DAQmx may fix this.
Best of luck,
03-20-2012 05:49 PM
Hi C2PO,
The DAQmx lowpass filter properties are for devices that have configurable lowpass filter hardware, like the NI 628x, NI PXIe-4300, some NI 61xx devices, and some SCXI modules. The NI 6341 doesn't have a configurable lowpass filter.
However, the code shouldn't hang in this case, it should return an error. Did you leave out the body of each if-statement in your post, or is this a deep set of nested if-statements? Either way, the example programs that Ryan C posted should help with the error handling.
Brad
03-20-2012 06:00 PM
Thanks Ryan and Brad for the replies - I'm doing a :
retVal = DAQmxSetAILowpassEnable(config->taskHandle, ss.str(), 1)
which throws the exception below for error -200077
throw exception(errorBuffer);//why this hangs in my application
but I get through that errror with:
retVal = DAQmxSetAILowpassEnable(config->taskHandle, ss.str(), 0)
but then I get errors like -200452 and "specifed property is not supported by the device etc."
So it now makes sense that this won't work on the NI 6341.
Thanks again.