Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read data from Counter NI9411 using C API?

Solved!
Go to solution

I'm using the NI-DAQmx C API to read data from a cDAQ-9188

I'm able to read analog voltages and digital inputs fine (NI9201 and NI375).

Having problems with Counters (measuring frequency) (NI9411).

I just get error "Some or all of your samples have not yet been acquired" after timeout.

 

My pseudo-source:

 

 

DAQmxCreateTask("", &taskHandle);
DAQmxCreateCIFreqChan(taskHandle, "cDAQ9188-189E9F4Mod1/ctr0", "", 1, 1000, DAQmx_Val_Hz, DAQmx_Val_Rising, DAQmx_Val_LowFreq1Ctr, 0.1, 1, NULL);
DAQmxCfgSampClkTiming(taskHandle, "pfi0", 5.0, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 5);
DAQmxStartTask(taskHandle);
DAQmxReadCounterU32(taskHandle, 5, 10.0, (uInt32*)data, 5, &read, NULL);

 Are my device names and everything else correct?

 

Thanks.

0 Kudos
Message 1 of 7
(3,382 Views)
Solution
Accepted by topic author pquiring

Have you compared it against the C api examples?  I believe you have the option to install the examples when you install the daqmx drivers.

 

If you have done that and it seems the same then I'd say you should try troubleshooting if you are producing any data at all.

 

-Bear

Regards,

Ben Johnson
ʕง•ᴥ•ʔง
0 Kudos
Message 2 of 7
(3,348 Views)

I'll see if I can find the examples.

I know there is data, it works fine is SignalExpress.

0 Kudos
Message 3 of 7
(3,345 Views)

Using the examples I changed my code to this:

 

 

DAQmxCreateTask("", &taskHandle);
DAQmxCreateCIFreqChan(taskHandle, "cDAQ9188-189E9F4Mod1/ctr0", "", 1, 1000, DAQmx_Val_Hz, DAQmx_Val_Rising, DAQmx_Val_LowFreq1Ctr, 0.1, 1, NULL);
DAQmxSetCIFreqTerm(taskHandle, "cDAQ9188-189E9F4Mod1/ctr0", "/cDAQ9188-189E9F4Mod1/pfi0");
DAQmxCfgImplicitTiming(taskHandle, DAQmx_Val_ContSamps, samples);
DAQmxStartTask(taskHandle); DAQmxReadCounterU32(taskHandle, 5, 10.0, (uInt32*)data, 5, &read, NULL);

But the data returned is VERY high.  I should be getting 100 - 200Hz but the data returned is 300,000Hz to 700,000Hz.

 

0 Kudos
Message 4 of 7
(3,341 Views)

Got it working!!!

Final code:

DAQmxCreateTask("", &taskHandle);
DAQmxCreateCIFreqChan(taskHandle, "cDAQ9188-189E9F4Mod1/ctr0", "", 1, 1000, DAQmx_Val_Hz, DAQmx_Val_Rising, DAQmx_Val_LowFreq1Ctr, 0.1, 1, NULL);
DAQmxSetCIFreqTerm(taskHandle, "cDAQ9188-189E9F4Mod1/ctr0", "/cDAQ9188-189E9F4Mod1/pfi0");
DAQmxCfgImplicitTiming(taskHandle, DAQmx_Val_ContSamps, samples);
DAQmxStartTask(taskHandle);
DAQmxReadCounterF64(taskHandle, 5, 10.0, (float64*)data, 5, &read, NULL);

Have to use the right ReadCounter function and use the ImplicitTiming.

 

Thanks!!

0 Kudos
Message 5 of 7
(3,339 Views)

We'll I've built my own data acquisition software using NI C/C++ API.

Check it out at http://jfdatalogger.sourceforge.net

 

Thanks

 

Message 6 of 7
(3,296 Views)

Props for posting your code!

 

Thanks for contributing.  Seems legit to me!

 

-Bear

Regards,

Ben Johnson
ʕง•ᴥ•ʔง
0 Kudos
Message 7 of 7
(3,279 Views)