Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read multiple analog channels simultaneously

Solved!
Go to solution

Hi,

 

I am trying to read two thermocouple channels on the NI-9211 board with a single task. It works great when there is only a single channel ("Dev1/ai0").

 

But when I try to add a second channel ("Dev1/ai0:1", or "Dev1/ai0:Dev1/ai1", or "Dev1/ai0,Dev1/ai1"), neither of them read anything at all.

 

Here is my code - I am using ANSI C API with continuous sampling and a callback:

double temp;

int32 CVICALLBACK DataReadyCallback(TaskHandle taskHandle, int32 everyNsamplesEventType,
uInt32 nSamples, void *callbackData);

void CreateTask()
{
TaskHandle taskHandle;
DAQmxCreateTask("", &taskHandle); DAQmxCreateAIThrmcplChan(taskHandle, "Dev1/ai0:1", "", 75, 1500, DAQmx_Val_Kelvins, DAQmx_Val_K_Type_TC, DAQmx_Val_BuiltIn, 0, NULL); DAQmxCfgSampClkTiming(taskHandle, NULL, 6.0f, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1); DAQmxRegisterEveryNSamplesEvent(taskHandle, DAQmx_Val_Acquired_Into_Buffer, 1, 0, DataReadyCallback, NULL); DAQmxStartTask(taskHandle);
}

int32 CVICALLBACK DataReadyCallback(TaskHandle taskHandle, int32 everyNsamplesEventType,
uInt32 nSamples, void *callbackData)
{
double buffer[4];
int32 numRead;

DAQmxReadAnalogF64(taskHandle, -1, 0.5, DAQmx_Val_GroupByChannel, buffer, 4, &numRead, NULL);

temp = buffer[0];
}

Any advice appreciated!

 

0 Kudos
Message 1 of 4
(3,840 Views)
Solution
Accepted by topic author Peter_09876

Hey Peter_09876!

 

Did you built this code from scratch?

 

It looks it is fine, but, you can try with an example we have available in C...you just need to go to All Programs->National Instruments->NI-DAQmx->Examples-> ANSI C-> Analog In

 

Try with those and let me know how it goes.

 

-Andrea G

National Instruments

Message 2 of 4
(3,779 Views)

Thank you Andrea - indeed, the example code works fine.

 

The problem with my code was that the sampling rate was too high, which I was able to find by plugging my parameters into the example and seeing what errors were reported. The maximum sampling rate on NI-9211 is dependent on the number of TC channels:

 

max_rate = 14.28 / (N +1)

 

where N is the number of TC channels being measured. So by setting it at 6.0 scans/s, I exceeded the 4.76 max rate for two channels.

Message 3 of 4
(3,769 Views)

Excellent Peter_09876 I am glad you manage to figure it out then!

 

-Andrea G

National Instruments

0 Kudos
Message 4 of 4
(3,752 Views)