07-16-2009 04:23 AM
Hi brothers and sisters;
I am trying to get 6 signals(6 chanels) of an F/T sensor that conected to NI USB-6251.
As I am a new user, I have tried with ANSI C Example programs. Here the one I used:
C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage\Cont Acq-Int Clk
ContAcq-IntClk.c
#include <stdio.h>
#include <NIDAQmx.h>
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData);
int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData);
int main(void)
{
int32 error=0;
TaskHandle taskHandle=0;
char errBuff[2048]={'\0'};
/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",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'};
static int totalRead=0;
int32 read=0;
float64 data[1000];
/*********************************************/
// DAQmx Read Code
/*********************************************/
DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,1000,10.0,DAQmx_Val_GroupByScanNumber,data,1000,&read,NULL));
if( read>0 ) {
printf("Acquired %d samples. Total %d\r",read,totalRead+=read);
fflush(stdout);
}
Error:
if( DAQmxFailed(error) ) {
DAQmxGetExtendedErrorInfo(errBuff,2048);
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
printf("DAQmx Error: %s\n",errBuff);
}
return 0;
}
int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData)
{
int32 error=0;
char errBuff[2048]={'\0'};
// Check to see if an error stopped the task.
DAQmxErrChk (status);
Error:
if( DAQmxFailed(error) ) {
DAQmxGetExtendedErrorInfo(errBuff,2048);
DAQmxClearTask(taskHandle);
printf("DAQmx Error: %s\n",errBuff);
}
return 0;
}
................................
I used VC++6.0 to compile it, but it does not work at all. Can you explain me which codes should I change in this program?
07-23-2009 11:27 PM
Hi camboljp,
Did you get any error message when you run the program?
If so, will you attach screenshot of the error message?
Regards,
Osamu Fujioka
Applications Engineer NIJ
07-24-2009 02:54 AM
Hi Osamu Fujioka
I tried to read the help documents, it worked. But there was another error message.
Here are what I changed
DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0:5","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",100000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,10));
DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,10,0,EveryNCallback,NULL));
DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,10,10.0,DAQmx_Val_GroupByScanNumber,data,600,&read,NULL));
if( read>0 ) {
//printf("Acquired %d samples. %f %f Total %d\r",read,data[0],data[1],totalRead+=read);
printf("%.4f\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f\n",data[0],data[1],data[2],data[3],data[4],data[5]);
fflush(stdout);
}
Error message is :
DAQmx Error: Measurements: Onboard device memory overflow. Because of system and
/or bus-bandwidth limitations, the driver could not read data from the device fa
st enough to keep up with the device throughput.
Reduce the sample rate, or reduce the number of programs your computer is execut
ing concurrently.
Task Name: _unnamedTask<0>
Status Code: -200361
Regards
camboljp
08-06-2009 08:59 PM
Hi camboljp,
You set sampling rate so fast that the PC cannot transfer all the sample data on the onboard memory before next samples start being acquired.
This is because the transfer rate through PCI bus where the board is connected is not as fast as the sampling rate.
To avoid this error, you may try the sampling rate from 10k to any lower value till this error disappears.
Regards,
Osamu Fujioka
Applications Engineer
NIJ