Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get multi channel reads using the NIDAQ library

Hi
 
USB 6008. Python
Can anyone tell me how I can read three channels simultaneously?
I tried "Dev/ai0:2" but this did not work. Using just Dev1/ai0 gives the correct result but I need this for 3 channels (simultaneuosly)
 
Thanks
       
# now, on with the program
        CHK(nidaq.DAQmxCreateTask("",ctypes.byref(taskHandle)))
        CHK(nidaq.DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",
                                           DAQmx_Val_Diff,                                  #DAQmx_Val_Diff,   #DAQmx_Val_RSE,       #DAQmx_Val_Cfg_Default,
                                           float64(-10.0),float64(10.0),
                                           DAQmx_Val_Volts,None))
        CHK(nidaq.DAQmxCfgSampClkTiming(taskHandle,"",float64(10000.0),
                                        DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,
                                        uInt64(max_num_samples)));
        CHK(nidaq.DAQmxStartTask(taskHandle))
        read = int32()
        CHK(nidaq.DAQmxReadAnalogF64(taskHandle,max_num_samples,float64(1.0),
                                     DAQmx_Val_GroupByChannel,data.ctypes.data,
                                     max_num_samples,ctypes.byref(read),None))
 
0 Kudos
Message 1 of 9
(4,489 Views)
0 Kudos
Message 2 of 9
(4,454 Views)

Hi Jochen

 

Thanks. I figured out the solution myself. I posted that solution for others 🙂

 

DaleFlow

 

0 Kudos
Message 3 of 9
(4,449 Views)
Hi Daleflow,

that's what I saw. I have just added the link to make it easier for other users to find the solution.

Jochen
0 Kudos
Message 4 of 9
(4,447 Views)

Hi I have the same problem please help I read your code but  could  not understand it very well:

Here is my code in c: I have multi channels, it gives me the buffer size error ,how can I read the data for each input from the channel and store it seperately??

DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,

"Dev1/ai0:9","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));

DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,

"",10000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));

DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,1000,0,EveryNCallback,NULL));

DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));

/*********************************************/


// DAQmx Start Code


/*********************************************/


DAQmxErrChk (DAQmxStartTask(taskHandle));

printf(

"Acquiring samples continuously. Press Enter to interrupt\n");

getchar();

Error:

if( DAQmxFailed(error) )

DAQmxGetExtendedErrorInfo(errBuff,2048);

if( taskHandle!=0 ) {

/*********************************************/


// DAQmx Stop Code


/*********************************************/


DAQmxStopTask(taskHandle);

DAQmxClearTask(taskHandle);

}

if( DAQmxFailed(error) )

printf(

"DAQmx Error: %s\n",errBuff);

printf(

"End of program, press Enter key to quit\n");

getchar();

return 0;

}

int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples,

void *callbackData)

{

int32       error=0;

char        errBuff[2048]={'\0'};

staticint  totalRead=0;

int32       read=0;

float64     data[1000];

int32 i=0;

/*********************************************/


// DAQmx Read Code


/*********************************************/


DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,1000,10.0,DAQmx_Val_GroupByScanNumber,data,1000,&read,NULL));

if( read>0 ) {

i=i+1;

printf(

"Acquired %d samples.Total %f\r",read,data[i]);

fflush(stdout);

}

0 Kudos
Message 5 of 9
(3,935 Views)

Hello darya,

 

take a look at this example:

 

Multi-Channel Acquisition with Multiple NI 4472 Devices -- CVI

http://zone.ni.com/devzone/cda/epd/p/id/4708

 

You'll just need the multi-channel acquisition part, which is in C, since it's a CVI example.

 

Kind regards,

Jannis

0 Kudos
Message 6 of 9
(3,837 Views)

Hi darya

 

Although I'm not a c programmer, I can tell you that the data from 1 read (3 channels) of the nidaq can be read as individual

dataitems like so (from the function in my example that returns "data"). This is a 3 channel get:

...

CHK(nidaq.DAQmxReadAnalogF64(taskHandle,max_num_samples,float64(1.0),                                     DAQmx_Val_GroupByChannel,data.ctypes.data,                                   

 max_num_samples,ctypes.byref(read),None))       

#print "Acquired %d points"%(read.value)               

if taskHandle.value != 0:           

nidaq.DAQmxStopTask(taskHandle)           

nidaq.DAQmxClearTask(taskHandle)               

return data

 

...

 

To read the returned data rounded to 2dp:

 

               v1 = round(data[0],2)               

               v2 = round(data[1],2)               

               v3 = round(data[2],2)

 

It's simply an array that can be split

 

Hope that helps

0 Kudos
Message 7 of 9
(3,830 Views)

hi,Thanks alot ,Actually I am  programming in java and decided to use JNI for
access to NIDAQ LIB.

 

I used DAQmxConfigureLogging(taskHandle,"C:\\example3.tdms"

 

I saved the data in the tdms file, now I have an issue with
reading data from this file,The thing I can not understand is for example when
we have 1000 samples per each channel,how it  will be stored in the data array :data1 data 2 data 3 data 1 data 2 data 3...................?until get the 1000 samples? another question do I need SQL DB for storing data if I have a large amount of data?

 

 

0 Kudos
Message 8 of 9
(3,819 Views)

Hello darya

 

I would imagine the data is in a mutiple array form

Here the Channel 2  and the 100th sample

               v3 = round(data[2][100],2)

 

In debug, start with a small data collection say 2 channels and 9 samples. You can easily see the structure in "data" then

 

I use a TEXT datatype to store the arrays of data in a SQL DB in my case as I don't need to index or search the plot. It really depends on what you want to do with the stored data afterwards and how you are going to query the data.

 

I would always start with a small sample rate until you are sure everything is working, then ramp up the sample rate to full speed.

 

Simon

 

 

0 Kudos
Message 9 of 9
(3,811 Views)