12-11-2007 01:24 PM
12-12-2007 04:58 PM
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!
01-30-2008 03:52 PM
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.
01-30-2008 03:58 PM
01-31-2008 05:39 PM
02-02-2008 12:22 PM
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);
}
.....
}
02-02-2008 12:27 PM
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 !!
02-04-2008 04:33 PM
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.02-05-2008 10:09 AM
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?
02-05-2008 10:44 AM