06-19-2008 05:40 PM
06-24-2008 02:41 AM
06-24-2008 05:48 AM
Hi Jochen
Thanks. I figured out the solution myself. I posted that solution for others 🙂
DaleFlow
06-24-2008 05:56 AM
09-02-2011 10:25 AM
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);
}
09-05-2011 10:25 AM
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
09-05-2011 01:24 PM
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
09-06-2011 10:14 AM
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?
09-06-2011 04:06 PM
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