Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Continuous data aquisition slow unless test panel opened first

I have a scanning system using a USB-6210 for data aquisition and  written in Visual C++ using NI-DAQmx. The data is sampled continuously on eight analog channels with an averaging of ten and the most recent sample is read from the buffer whenever the program needs a measurement. The code works but is slower than expected (15.3 milliseconds per measurement). The time drops to 1.95 milliseconds and the program works perfectly if the test panel for the device is opened and closed before running the program. This leads me to believe my program is failing to set some parameter that is set when the test panel is opened. Do you know what is not being set or what else would cause the difference? Thank you. The relevant portion of my code is below:

Initialization
DAQmxStopTask(this->dthReadVolt); // to clear previous task if existing
DAQmxClearTask(this->dthReadVolt);

str = "PMDet/ai0";
if(this->iNumChannels > 0) {
    str << ":" << (this->iNumChannels-1);
}
DAQmxCreateTask("ReadVolt", &this->dthReadVolt);
DAQmxCreateAIVoltageChan(this->dthReadVolt, str.c_str(), "", DAQmx_Val_Diff, MinVal, MaxVal, DAQmx_Val_Volts, NULL);
if(iNumChannels == 1)
    SamplesPerChannel = this->dSampleRateUpper;
else
    SamplesPerChannel = this->dSampleRate/this->iNumChannels;
DAQmxCfgSampClkTiming(this->dthReadVolt, NULL, SamplesPerChannel, DAQmx_Val_Rising, DAQmx_Val_ContSamps,       (uInt64)this->iNumAverage);

DAQmxSetReadOverWrite(this->dthReadVolt, DAQmx_Val_OverwriteUnreadSamps);
DAQmxSetReadRelativeTo(this->dthReadVolt, DAQmx_Val_MostRecentSamp);
DAQmxSetReadOffset(this->dthReadVolt, -1);

DAQmxStartTask(this->dthReadVolt);

Taking a measurement
DAQErrorCode = DAQmxReadAnalogF64(dthReadVolt, (int)this->iNumAverage, 10.0, DAQmx_Val_GroupByScanNumber, &this->vdAverageVolt[0], this->iTotalAverageLength, &this->iRead, NULL);

0 Kudos
Message 1 of 9
(4,769 Views)
Has anyone had a chance to look at this or any ideas about what the cause would be? The project is currently waiting on this problem.
0 Kudos
Message 2 of 9
(4,752 Views)
Hi,
 
If you look at the example programs that are installed with DAQmx, the events are registered before making any of the readings.  Callbacks are using in the example program which makes the execution more efficient.  What version of DAQmx do you have?  If you have a version higher than 8.5 then your example programs will be located here.
 
C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C
 
Here is a section of the example code.
 
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();
 
>>>>
 
The time drops to 1.95 milliseconds and the program works perfectly if the test panel for the device is opened and closed before running the program. This leads me to believe my program is failing to set some parameter that is set when the test panel is opened. Do you know what is not being set or what else would cause the difference? Thank you. The relevant portion of my code is below:
If I understand correctly, you are just opening and closing the test panel before running the program?  Could you try a basic reset of the device before you run the program and see if that helps?
 
The command to reset the device is:

DAQmxResetDevice

int32 DAQmxResetDevice (const char deviceName[]);

Hope some of this helps.
 
Regards,
 
 
 
 
Raajit L
National Instruments
0 Kudos
Message 3 of 9
(4,733 Views)
Greetings,
  Thank you for your suggestions and sorry about my delay in replying, unfortunately neither suggestion solved the problem. Adding the reset of the device resulted in no change. Callbacks are not very well suited for my program since it reads only the most recent sample out of the buffer whenever the rest of the program is in position (asyncronous) and ignors all other data collected. I did modify an example code using callbacks (included below) and experienced the same issue with slower speeds unless the device test panel is opened first.

Further tests have shown that the slowdown only manifests when the ReadRelativeTo property is set to DAQmx_Val_MostRecentSamp, and also that opening any NI program that communicates to the DAQ device solves the issue.The problem has also gone away, in a few cases, after the computer has simply been in use for several hours. A possible cause may be the computer allocation of USB resources. I am using DAQmx 8.5 and am running two DAQ devices (USB-6210 and USB-6501) through a USB hub, though only the USB-6210 is operated at high speeds.

Do you have any further suggestions or are you aware of any issues with allocating computer USB resources, particularly any addressed in official NI software? The modified example code is below.

Thanks, Andrew


A modified version of ANSI C Example program: 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,"PMDet/ai0:7","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
    DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",31250.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,10));

    DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,10,0,EveryNCallback,NULL));
    DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));

    DAQmxErrChk (DAQmxSetReadOverWrite(taskHandle, DAQmx_Val_OverwriteUnreadSamps));
    DAQmxErrChk (DAQmxSetReadRelativeTo(taskHandle, DAQmx_Val_MostRecentSamp));
    DAQmxErrChk (DAQmxSetReadOffset(taskHandle, -1));

    /*********************************************/
    // 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,10,10.0,DAQmx_Val_GroupByScanNumber,data,80,&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;
}




Message Edited by Andrew Mac on 07-07-2008 03:10 PM
0 Kudos
Message 4 of 9
(4,671 Views)
Andrew,

Is this USB hub that you mention an externally powered hub?  Does the computer that you are using have more than one USB port and maybe you can plug the instruments into two different USB ports, just as a troubleshooting step.  Also, if you plug in only one instrument at a time, does this problem still exist?
and also that opening any NI program that communicates to the DAQ device solves the issue.
When you mention any NI program, you mean something like the test panels in Measurement and Automation Explorer?  Is this NI program communicating with the DAQ device while your program is running or before the program is running like you mentioned in your last post?

I am leaning towards the USB hub being a potential problem.  Trying the DAQ instruments seperately, without the hub might shed some more light on this issue.  If you have the model number of the USB hub that would help as well.

Thanks a lot.

Regards,
Raajit L
National Instruments
0 Kudos
Message 5 of 9
(4,645 Views)
Andrew,

I did have another couple of questions.  How are you measuring this time?  Are you just measuring the time to acquire the first sample, or are you taking an average of multiple samples?  The reason I ask this is because in any DAQ program, a few DLLs are loaded before making any measurements, so the time taken for the first sample to be acquired is going to be a little longer.  Once that happens the time between iterations should be shorter and similar.

One thing we could try is, could you run your program twice.  Since all those DLLs should be loaded the first time you run your program, I expect that the second time you run your program, the time taken should be shorter.  Could you please test that and post back with the results. 

Test panels in Measurement and Automation explorer also just run DAQ code, which will also load the DAQ DLLs, which might explain why it works fine after you run the test panels.

Looking forward to hearing from you.

Regards,
Raajit L
National Instruments
0 Kudos
Message 6 of 9
(4,639 Views)
Raajit,
     The USB hub is not externally powered (by Kensington, model #K33399).  However, I tried running the DAQ device directly from a computer USB port, as you suggested, with the second DAQ device not connected; and the behavior remains the same.

     By NI program I mean that I have observed this behavior with the test panels in Measurement and Automation Explorer, tasks run out of Measurement and Automation Explorer, and the DAQ Diagnostic Utility 2.0 (http://joule.ni.com/nidu/cds/view/p/id/566/lang/en). These would all be before the program is running.

     To measure the time the continuous aquisition task is first started, several seconds later 100 read operations of 10 samples per channel (80 samples total) each are averaged. The program also continues to experience problems as it runs (observed for several minutes) because the DAQ reads are slower than expected and causing timing issues within the larger program. I have run the program several times in a row with no change.

Thank you for your continued help,
Andrew

0 Kudos
Message 7 of 9
(4,626 Views)

Hi,

   

I have the same problem and it is not a usb problem because I tried with others multifunction cards (NI USB-6008, NI PCI-6220 and NI PCI-MIO-16XE-50) with the same results.

 

My first solution was to make a reset device with DAQmxResetDevice but it did not work. The card's configuration is exactly the same as Andrew made and I read 10 samples at a time, so I expected a 10 ms read time but this time was 15 ms.

 

I modified the example C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Cont Acq-Int Clk  to capture the time and the problem remains unless the test panel for the device is opened and closed before running the program.

 

It could be a dll problem? 

 

I wonder if you have the solution and in this case, I will be very grateful if you could help me.

 

Thanks in advance

 

Teresa 

 

 

 

0 Kudos
Message 8 of 9
(4,438 Views)

Teresa,

  I have not been able to find a solution for this problem. My current procedure is simply to open and close the test panel every time the computer is turned on, before using the DAQ device.

 

Sorry I cannot be of more assistance,

Andrew

0 Kudos
Message 9 of 9
(4,407 Views)