Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Urgent: Please help. how to solve the time delay during buffer read and write using vc++

I need to continuously acquire data from daqmx card, write into a file and at the same time corelate (in terms of time) the data with signals from other instruments. The current problem is that there is time delay during read and write data into buffer,thus causing misalignment of the data from multiple instruments. Is there a way to solve  the delay? or Is there a way to mark the time of the data acquisition in the buffer?  If I know the starting time (e.g. 0) of data acquisition and sampling rate (e.g. 1kHz), can I simply add 1ms to each data sample in the buffer? The current code is shown below.

 

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));// Every 50 samples the EveryNSamplesEvent will be trigured, to reduce time delay.
  DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));

  DAQmxErrChk (DAQmxStartTask(taskHandle));

......

}

 

int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
 {

 DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,50,10.0,DAQmx_Val_GroupByScanNumber,data,50*15,&read,NULL));
   //memcpy(l_data,data,6000);
  SetEvent(hEvent);
l_usstatus_e[0]=g_usstatus[0];// signals from other instruments that need to be corelated with the data from daq cards.
 l_optstatus_e[0]=g_optstatus[0];


 if( read>0 ) // write data into file
 {

   //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]);

.......

}

 

0 Kudos
Message 1 of 4
(6,846 Views)
Hello tgy,

Please refrain from placing the same post on multiple boards. Here is a link to the active thread.

Regards,
Dan King

0 Kudos
Message 2 of 4
(6,824 Views)
Sorry. I don't know where is the correct forum for the post.  Is there a way to directly move the post if want to transfer to another forum?
0 Kudos
Message 3 of 4
(6,821 Views)
Hello kgy,

It is a bit of a judgment call. You should just choose the board that you think has the most to do with your issue. For example, this issue was much more focused on setting up your data acquisition task than the Measurement Studio environment/tools, so the MultifunctionDAQ board would have been the best place for it. As for moving your post to another board, I do not believe that is possible.

Regards,
Dan King

0 Kudos
Message 4 of 4
(6,808 Views)