Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Help please:DAQ when you create a virtual channel with different inputs in c

Hi 

I am writing a code with c to acquire a continuous amount of data using the DAQ device's internal clock.

I have to read different analog inputs from my 6210 device

 

I defined the virtual channel like this:

DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai:1:9"   

 

I do not know how to read different inputs from one channel  with DAQmxReadAnalogF64,maybe I need to create a channel for each inputs?

 

Many thanks

0 Kudos
Message 1 of 13
(3,490 Views)

Welcome to the NI Forums!

 

Have you seen the Acq-IntClk example in the Example Finder? It can be found in <LabWindows CVI> » Help » Find Examples... » Hardware Input and Output » Analogue Measurements

 

You were right to suggest that using the DAQmxReadAnalogF64 function would be useful in this instance; by referencing the correct task with the appropriate variables, you can perform a read function and allow the returned data array to be iterated through. In this example you select a single channel which is acquired for a finite amount of samples; but it's easier to understand how the read function works in code. 

 

For continuous acquisition, check out the ContAcq-IntClk.proj. You'll see that this code is developed modularly to incorporate multiple channels, through this code:

 

DAQmxErrChk(DAQmxReadAnalogF64(taskHandle,nSamples,10.0,DAQmx_Val_GroupByScanNumber,gData,nSamples*gNumChannels,&numRead,NULL));

if( numRead>0 ){

PlotStripChart(panelHandle,PANEL_STRIPCHART,gData,numRead*gNumChannels,0,0,VAL_DOUBLE);

 

This will allow you to acquire multiple channel data. As you mentioned, by modifying the code you can read multiple channels by specifying them in the format you used. For example, adjacent channels 0,1 and 2 in device Dev1 can be referred to as Dev1/ai0:2 and channels 0 to 2 and 7 as Dev1/ai0:2,Dev1/ai7 (As this example contains a comma to refer to non-adjacent channels in the task).

 

I hope this helps you!


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)

0 Kudos
Message 2 of 13
(3,454 Views)

 

Hi Alex many thanks for your reply .I used the example but it is not for multi inputs.

 

Instead of using read I used this method
DAQmxConfigureLogging(taskHandle,"C:\\example.tdms" Now I am looking for a way to read the data from the tdms file.

 

If I used the DAQmxReadAnalogF64 how can I get the data for each input separately? for example I had 1000 samples per channel  and ai1:3     ai1= data[1] ai2=data[2]?.........1000samples....

 

Another question do I need  asql db to read a large amount of data and  analyse it?

 

0 Kudos
Message 3 of 13
(3,448 Views)

Hi darya,

 

I've been working on acquiring individual channel information through LabWindows CVI through a task configured for multiple channels worth of data. This tutorial on DIO agrees with what you say and gives examples on individual and multiple channels worth of digital data.

 

In the instance of analogue data, I've found that to read a single set of samples from a task which is acquiring from multiple channels you can reference the required channel through an array whilst also accommodating the number of samples to read appropriately.

 

A channel configured as:

DAQmxCreateTask("",&taskHandle);

DAQmxCreateAIVoltageChan(taskHandle,"MSeriesAlex/AI0:3","",DAQmx_Val_Cfg_Default,min,max,DAQmx_Val_Volts,NULL);

DAQmxCfgSampClkTiming(taskHandle,"",rate,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,sampsPerChan);

DAQmxGetTaskAttribute(taskHandle,DAQmx_Task_NumChans,&numChannels);

 

Can have all channels sampled with the following code:

DAQmxReadAnalogF64(taskHandle,sampsPerChan,10.0,DAQmx_Val_GroupByChannel,data,sampsPerChan*numChannels,&numRead,NULL);

 

The AI1 input channel read through the following code:

DAQmxReadAnalogF64(taskHandle,sampsPerChan,10.0,DAQmx_Val_GroupByChannel,&data[1],sampsPerChan,&numRead,NULL);

The ampersand is a necessity in order for the addressing scheme of the data pointer to provide us with the correct channel information.

 

For storing data it depends on what quantity you mean by a large amount of data.  For smaller cases it may be better to write to a spreadsheet-oriented file and for enormous amounts of data with high performance you could mine data with DIAdem! It really depends on the situation, however I'd recommend analysing your application requirements and seeing which different storage implementations is the most suitable.


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)

0 Kudos
Message 4 of 13
(3,438 Views)

Hi Alex thanks a lot for your help.

0 Kudos
Message 5 of 13
(3,432 Views)

No problem at all. I had good fun playing around with the example codes to implement the right solution!


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)

0 Kudos
Message 6 of 13
(3,422 Views)

Hi again Alex

 

Thanks a lot for your help

It seems this solution is not working for me for example  for channel 9 with 5 samples

DAQmxReadAnalogF64(taskHandle,5,10.0,DAQmx_Val_GroupByChannel,&data[9],sampsPerChan,&numRead,NULL);

for (i=0;i<5;i++)

printf("Acquired %d points\n %f",read,data[i]);when I put data instead of &data[9] it works but my
problems is how to refer to each  channel separately .

 

I descided to use SQL since I am using java, and using the tdms file would make the project much more complicated....

 

Regards

Darya

0 Kudos
Message 7 of 13
(3,411 Views)

Hi darya,

 

I'm not sure I understand your question. Hopefully this will help:

 

for(int i=0;i<10;i++){

printf("Acquired %d points \n %f",read,&data[i]);//This will read all data points from each individual channel, from AI0 to AI9.

}

 

Outside of a for loop, the data from this channel could be directly referenced with data[9].

 

Are you receiving any error messages?

 

Regards,


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)

0 Kudos
Message 8 of 13
(3,408 Views)

Hi  Alex

thanks for your reply

 

sorry I can not understand whats happening  when we run this method: DAQmxReadAnalogF64(taskHandle,sampsPerChan,10.0,DAQmx_Val_GroupByChannel,&data[1],sampsPerChan,&numRead,NULL);

Doese it read only AI1 input (index to ai1)?And if I want to save this data or print 5 samples for this input: 

printf("Acquired %d points\n %f",read,?    what is the variable in here  ??                       );

 

I tried &ai[1] but doesnt work ,

 

Many thankssssssssss

0 Kudos
Message 9 of 13
(3,334 Views)

Hi darya,

 

Can you please upload your code to the forums?

I'll try to modify it to read the individual channel and explain the changes that I have made in a follow up post.

 

Best regards,


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)

0 Kudos
Message 10 of 13
(3,316 Views)