Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Please help me on error -200284 for usb6008 data A/D

Hi,
 
I am working on the A/D using usb6008, I program in visual c++.  I create a dialog to test the function of sample program: contAcquireNChan.c               in  NI-DAQmx Base.  I just changed the mode to DAQmx_Val_FiniteSamps and each time I just want to get several data. I used a button to start the a/d. The following is the code. The problem is very strange that while I click the start button for the sixth time, this error -200284 will occur when calling this function:
 DAQmxErrChk (DAQmxBaseReadAnalogF64taskHandle,pointsToRead,timeout,DAQmx_Val_GroupByScanNumber,data,2,&pointsRead,NULL));
 
The discription of this error is:
"Some or all of the samples requested have not yet been acquired.
To wait for the samples to become available use a longer read timeout or read later in your program. To make the samples available sooner, increase the sample rate."
 
I do not know what happened. And how to solve this problem. Please help me.
 
The following is the code:
 
void CBTTest001Dlg::OnStart()
{
//////////////////////////////////////////////////
 
 
   // Task parameters
    int32       error = 0;
    TaskHandle  taskHandle = 0;
    char        errBuff[2048]={'\0'};
    time_t      startTime;
    bool32      done=0;
    // Channel parameters
    char        chan[] = "Dev1/ai0";
    float64     min = -10.0;
    float64     max = 10.0;
    // Timing parameters
    char        clockSource[] = "OnboardClock";
    uInt64      samplesPerChan = 2;
    float64     sampleRate = 2000.0;
    // Data read parameters
    #define     bufferSize (uInt32)1000
    float64     data[bufferSize * 5];
    int32       pointsToRead = bufferSize;
    int32       pointsRead;
    float64     timeout = 10.0;
    int32       totalRead = 0;
 
 
 
 index++;
 if(index==6)
 {
    int a =0;
  ;
 }
/////////////////////////////////////////////////// 
 m_bWorkFlag = true; 
  double a1= data[0];
  double a2= data[1];
  double a3= data[2];
  double a4= data[3];
  DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));
  DAQmxErrChk (DAQmxBaseCreateAIVoltageChan(taskHandle,chan,"",DAQmx_Val_RSE,min,max,DAQmx_Val_Volts,NULL));
  DAQmxErrChk (DAQmxBaseCfgSampClkTiming(taskHandle,clockSource,sampleRate,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,samplesPerChan));
  DAQmxErrChk (DAQmxBaseCfgInputBuffer(taskHandle,2000)); //use a 100,000 sample DMA buffer
  DAQmxErrChk (DAQmxBaseStartTask(taskHandle));
  DAQmxErrChk (DAQmxBaseReadAnalogF64(taskHandle,pointsToRead,timeout,DAQmx_Val_GroupByScanNumber,data,2,&pointsRead,NULL));
 //    printf("\nAcquired %d total samples.\n",totalRead);
  m_fAnalog1 = data[0];
  m_fAnalog2 = data[1];
  m_fAnalog3 = data[2];
  m_fAnalog4 = data[3];
  m_fAnalog5 = data[4];
  UpdateData(false);
  if(taskHandle != 0) {
//   DAQmxBaseStopTask (taskHandle);
   DAQmxBaseClearTask (taskHandle);
  }
 return;
Error:
    if( DAQmxFailed(error) )
        DAQmxBaseGetExtendedErrorInfo(errBuff,2048);
    if( DAQmxFailed(error) )
        printf("DAQmxBase Error: %s\n",errBuff);
}
 
0 Kudos
Message 1 of 10
(9,622 Views)

Hello Leonard.ma,

The error your are receiving is a timeout error.  It is saying that the DAQmxBaseReadAnalogF64 has exceeded the time allowed (in your code 10s) to read the specified number of points (which is your buffersize of 1000).  Since you changed the acquisition mode to Finite Samples and you specified a Samples Per Channel of 2, your device is only acquiring a total of 2 samples per channel. So basically, you are waiting for 1000 points when you are only getting 2. 

The way to fix this would be to set your samplesPerChan=pointsToRead.  This would be sure that you read the same number of points that you are getting.  The other way to go about this is to set your pointsToRead to -1, which means to read all available points.  You could then put the read in a loop until all of your points have been read out. If you do this second method, it would be much easier to change to continuous sampling in the future.

I am a little confused as to what you mean by "while I click the start button for the sixth time, this error -200284 will occur."  Do you mean that you click your start button 6x and it works the first 5?  Or could it be that you are clicking the start button 6 times in your 10s timeout period?  If it is the former, then we will have to look for other reasons, however if it is the later, then making the changes I suggested should fix the problem.

I hope this is helpful, please post back if you have questions!

Neal M.
Applications Engineering       National Instruments        www.ni.com/support
0 Kudos
Message 2 of 10
(9,602 Views)

Thank you so much for your help!

The case is the former "click start button 6x and it works the first 5". I thought I solved the problem a month ago and I left it beside, but I relized now that I did not solve it. I added:

   DAQmxBaseStopTask (taskHandle);

and it work well. but when I move the data acquire code to onTimer function (I want acquire the data 3 times a second), the program 'halt"  after half minute (sometimes even faster).

I tried to move the   code:

 DAQmxErrChk (DAQmxBaseStartTask(taskHandle));

out of the onTimer to OnInitialUpdate()  and will not stop the task unless I push a button. This time the program will not halt. But the data acquired is not right. How comes it? Do you have any solution? Please help me. Thanks a lot.

0 Kudos
Message 3 of 10
(9,406 Views)
By the way, When it halt. The CPU usage in task manager is 100%. The program and labview runtime are all "no responding". If I end the program, the system is OK. Thanks.
0 Kudos
Message 4 of 10
(9,404 Views)
Hello again Leonard.ma,

I am a little confused as to what is going on and how your code is organized.  You say that you thought you solved the issue but did you not?   Did you add the stop task function before and that is what you thought solved the issue?  I am not sure what could be causing your system to hang after 30 seconds.  The only thing I can think of that would do this is a function is not completing and is not timing out.

Is there a reason that you are using DAQmx Base?  The reason I ask is because our full driver, DAQmx, has many more example programs (including a finite voltage acquisition).  It also has much more functionality and can do much more with our hardware than DAQmx Base.  DAQmx Base was designed for use on operating systems other than Windows, however because you are using Measurement Studio, I suspect you are on a Windows machine.

If you could possibly attach your code, I could try and run it on my computer and see if I can figure out what is going on.
Neal M.
Applications Engineering       National Instruments        www.ni.com/support
0 Kudos
Message 5 of 10
(9,378 Views)

Dear Neal,

Thank you so much !!

"DAQmx Base was designed for use on operating systems other than Windows". Maybe that's the reason why I always met problems.  I am using windows now !! The only reason for me to use DAQmx Base is that it comes with the USB6008 device so that I think NI recommend to use it ! I also downloaded DAQmx from NI but I did not tried it (in fact it took me several hours to switch the firmware back to DAQmx Base ). I will try It now and tell you the result.

"You say that you thought you solved the issue but did you not?"

Yes.

" Did you add the stop task function before and that is what you thought solved the issue? "

Yes.

I started from the example and do some modifications. First I met -200284 error and I found it is the caused by wrong number of data to be read. I changed to finite namber data read.

Then I met sixth reading problem, at that time I use a button clicking to read the data.when I read for the sixth time, It will occur (I forgot the phenomena). I added a  stop task function and I thoought I solved the problem. I knew for a finite number data reading, stop function is not needed, but I do not have any other method so I tried it. "sixth reading problem" solved, but When I move the data reading function to ontimer function recently. The program will halt -- take 99% of CPU time after 30 second of reading (sometime several minutes, sometimes several seconds). If I move the start task back to OnInitialUpdate() function and cancel stop function, halt error will not occur but the data I read in not correct. That is the whole thing. The following is the code relative to the data read.

Initialization;

void Ctest2Dlg::OnInitialUpdate()

{.....

   DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));
  DAQmxErrChk (DAQmxBaseCreateAIVoltageChan(taskHandle,chan,"",DAQmx_Val_RSE,min,max,DAQmx_Val_Volts,NULL));
  DAQmxErrChk (DAQmxBaseCfgSampClkTiming(taskHandle,clockSource,sampleRate,DAQmx_Val_Rising,DAQmx_Val_ContSamps ,samplesPerChan));

.....
 }

Data read

void Ctest2Dlg::OnTimer(UINT nIDEvent)

{

.....

  if(taskHandle != 0)
  {
     DAQmxErrChk (DAQmxBaseStartTask(taskHandle));

   DAQmxErrChk (DAQmxBaseReadAnalogF64(taskHandle,pointsToRead,timeout,DAQmx_Val_GroupByScanNumber,data,100,&pointsRead,NULL));
   
   DAQmxBaseStopTask (taskHandle);
  }

.....

}

 

0 Kudos
Message 6 of 10
(9,371 Views)

Definition of parameter:

#include "NIDAQmxBase.h"
 
//////////////////////////////////////////////////
 
 
   // Task parameters
 int   TaskOnOff = 0;
    int32       error = 0;
    TaskHandle  taskHandle = 0;
    char        errBuff[2048]={'\0'};
    time_t      startTime;
    bool32      done=0;

    // Channel parameters
    char        chan[] = "Dev1/ai0,Dev1/ai1,Dev1/ai2,Dev1/ai3,Dev1/ai4";
    float64     min = -10.0;
    float64     max = 10.0;

    // Timing parameters
    char        clockSource[] = "OnboardClock";
    uInt64      samplesPerChan = 1;
    float64     sampleRate = 1000.0;

    // Data read parameters
    #define     bufferSize (uInt32)1000
    float64     data[100];
    int32       pointsToRead = 1;
    int32       pointsRead;
    float64     timeout = 3.0;
    int32       totalRead = 0;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

I tried many times, but can not solve the problem. I appreciate you help so much !!  

0 Kudos
Message 7 of 10
(9,370 Views)

Hi Leonard,

You were on the right path when you began to download DAQmx from the ni.com website and switch over your firmware. Like Neal said, there is no advantageous reason to use DAQmx Base in a Windows Operating System. If you do make the switch to DAQmx then there are a number of Visual C++ examples that utilize finite acquisition. These can be found on your computer in a file location similar to the following: C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage.

The Knowledge Base Document NI-DAQmx, NI-VISA, and NI-488.2 Visual C++ Example Locations has the location where DAQmx examples can be found in various operating systems.

I hope that thus helps, Mallori M.
Mallori M
National Instruments
Sr Group Manager, Education Services

ni.com/training
0 Kudos
Message 8 of 10
(9,335 Views)
Hi mallorim ,
 
Thanks you so much for reply reply ! And also thanks Neal .

I already solved all the problem by using DAQmx . From my understanding, users will not get any advantage  to use DAQmx Base in a Windows Operating System. On the other hand, the only thing they will get is disadvantage. Am I right?


0 Kudos
Message 9 of 10
(9,324 Views)
Hi Leonard,
 
Glad to hear that you were able to solve your problem.
 
With regards to DAQmx Base, rather, I should have said that I could see no advantages for you to be using DAQmx Base.  National Instruments strongly recommends developers creating applications for Windows-based systems should consider using the latest in full-featured NI-DAQmx.  However, if for instance, you were developing an application that would in the future be moved to and used on systems not supported by DAQmx, using DAQmx Base for development would be highly advantageous.
 
Regards, Mallori  M.
Mallori M
National Instruments
Sr Group Manager, Education Services

ni.com/training
0 Kudos
Message 10 of 10
(9,318 Views)