03-10-2009 10:29 PM
here is my codes for continuously data aquisition:
void DataCollectionWin::ConnectDAQ()
{
DAQmxErrChk(DAQmxCreateTask ("", &taskHandle));
DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0,Dev1/ai1,Dev1/ai2,Dev1/ai3,Dev1/ai4,Dev1/ai5,Dev1/ai16,Dev1/ai17,Dev1/ai18,Dev1/ai19,Dev1/ai20,Dev1/ai21,Dev1/ai6,Dev1/ai7,Dev1/ai22","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle,"",1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,60000));
DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,50,0,EveryNCallback,NULL));
DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));
DAQmxErrChk (DAQmxStartTask(taskHandle));
}
int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData) // read most recent 50 data samples and save to file
{
DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,50,10.0,DAQmx_Val_GroupByScanNumber,data,50*15,&read,NULL));
if( read>0 )
{
//indicator=1;
for (i=0;i<read;i++)
{ //fprintf(datafile,"%d\t",i);
fprintf(datafile,"%c\t",l_usstatus_s[0]);
fprintf(datafile,"%c\t",l_usstatus_e[0]);
fprintf(datafile,"%c\t",l_optstatus_s[0]);
fprintf(datafile,"%c\t",l_optstatus_e[0]);
fprintf(datafile,"%.2f\t",data[15*i]);
// sprintf( pszTemp, "%f", data[6*i]);
// pListCtrl->SetItemText(0, 2, pszTemp);
//pWnd->m_trackinglist.SetItemText(0, 2, pszTemp);
fprintf(datafile,"%.2f\t",data[15*i+1]);
fprintf(datafile,"%.2f\t",data[15*i+2]);
fprintf(datafile,"%.2f\t",data[15*i+3]);
fprintf(datafile,"%.2f\t",data[15*i+4]);
fprintf(datafile,"%.2f\t",data[15*i+5]);
fprintf(datafile,"%.2f\t",data[15*i+6]);
fprintf(datafile,"%.2f\t",data[15*i+7]);
fprintf(datafile,"%.2f\t",data[15*i+8]);
fprintf(datafile,"%.2f\t",data[15*i+9]);
fprintf(datafile,"%.2f\t",data[15*i+10]);
fprintf(datafile,"%.2f\t",data[15*i+11]);
fprintf(datafile,"%.2f\t",data[15*i+12]*5);
fprintf(datafile,"%.2f\t",data[15*i+13]*5);
fprintf(datafile,"%.2f\n",data[15*i+14]*5);
}
fflush(stdout);
}
}
how to set the property nodes in vc, so that only the most recent 50 samples in the buffer will be read out and saved into a file? THank you!
03-10-2009 10:55 PM
how to set the read properties using c code, as in labview:
DAQmxRead.RelativeTo=MostRecentSample
DAQmxRead.OverwriteMode=OverwiteUnreadSamples
03-11-2009 04:49 PM
03-12-2009 12:24 PM
Hello,
I would take a look at manipulating one of the ANSI C shipping examples. Take a look at the example called Acq-Int Clk located at the following file path.
C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage
These examples should be located there as long as you've installed support for ANSI C with your DAQmx install.
In order to see only the last 50 samples, you could create a FIFO that is 50 elements long and set your DAQmx read call to fetch 50 samples with each call.Then as you retrieve 50 samples each iteration, you can fill your FIFO and then only display the elements from that FIFO. Then once the program is finished you'll only have the last 50.
For information about the C functions for DAQmx check out the NI DAQmx C Reference Help. You can find it in your Start menu under National Instruments>>NI-DAQ>>Documentation.
Chris