09-12-2011 05:55 AM
Hi Alex thanks I used the NI sample code(Acq-IntClk.c) when I use &data[9] in printf it does not print the ai9 samples.
#define
DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
int
main(void)
{
int32 error=0;
TaskHandle taskHandle=0;
int32 read;
float64 data[4000];
char errBuff[2048]={'\0'};
int i=0;
/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateTask(
"",&taskHandle));
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_FiniteSamps,1000));
/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk (DAQmxStartTask(taskHandle));
/*********************************************/
// DAQmx Read Code
/*********************************************/
DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,5,10.0,DAQmx_Val_GroupByChannel,&data[9],000,&read,NULL));
printf(
"Acquired %d points\n %f",read,&data[9]);
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;
}
09-13-2011 09:11 AM
Hi darya,
Sorry I keep taking so long to respond; I've been having a play around with LabWindows to try and derive the functionality that you're requesting and I think I can now explain a simple way of grabbing the data, by exploiting the fact that all of our channel information can be ground by their channel values.
DAQmx_Val_GroupByChannel
Build the array of data in accordance to their channel information, for example:
All data sequentially read from four different channels are read into the buffer in this format: 0 1 2 3 0 1 2 3 0 1 2 3.
However, by grouping the data by channel, we construct the array as follows: 000 111 222 333; by knowing where these positions in the array are, we can grab only specific array subsets that we want to process; subsets that match the number of samples and the channel offset!
In the example below, I have produced a very basic CVI which demonstrates this behaviour via use of a function called readChannelData. Using a For Loop, we can grab only data from a specific channel by manipulating the array with knowledge of the total number of samples per channel and each channel offset would have in the array. If you need anything clarifiying, get in touch:
#include "userint.h";
#include "stdio.h";
#include "NIDAQmx.h";
//Prototype before call.
float64* readChannelData(float64 *prototypeData,int channelToRead);
//Initialise global variables.
static int sampleRate = 1500.0;
static int numberOfSamples = 1000;
static int numberOfChannels = 4;
int main(){
//Initialise local variables.
TaskHandle taskHandle = 0;
int maximumVoltage = 10.0;
int minimumVoltage = -10.0;
int samplesPerChannel = 1000;
float64 gatheredData[numberOfChannels*numberOfSamples];
//Initialise the finite DAQ task.
DAQmxCreateTask("MultipleVoltageTask",&taskHandle);
//Initialise the voltage channel.
DAQmxCreateAIVoltageChan(taskHandle,"Dev3/ai0:1","",DAQmx_Val_Cfg_Default,minimumVoltage,maximumVoltage,DAQmx_Val_Volts,NULL);
//Define the Sample Clock timing for the device.
DAQmxCfgSampClkTiming(taskHandle,"",sampleRate,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,numberOfSamples);
//Begin task?
printf("Press enter to start the multiple channel voltage acquisition.\n");
getchar();//Start the task, gather finite samples.
DAQmxStartTask(taskHandle);
//Read the data.
DAQmxReadAnalogF64(taskHandle,DAQmx_Val_Auto,10.0,DAQmx_Val_GroupByChannel,gatheredData,numberOfChannels*numberOfSamples,&samplesPerChannel,NULL);//Exit the task.
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
// Exit the program.
printf("Acquisition has ended. Press the enter key to exit.");
getchar();
return 0;
}
//A function which iterates through the total set of data and exploits that the data comes in the format of DAQmx_Val_GroupByChannel to only grab relevant data.
float64* readChannelData(float64 *prototypeData,int channelToRead){
float64 prototypeArray[numberOfSamples];
for(int i = 0;i<numberOfSamples;i++){
prototypeArray[i] = prototypeData[(numberOfSamples*channelToRead)+i];
}
return prototypeArray;
}
09-22-2011 04:57 AM
Hi Alex
Many Many thanks for your help and effort ,I will run this code ,hopefully will not be back again here:womanvery-happy: