10-07-2010 03:17 PM
Ok great. Remember to map sample size and channel count to bytes.
For example, to transfer 8 kiB of data being generated by four 24-bit channels:
(8192 bytes) / [ (4 channels) * (4 bytes/sample) ] = 512 samples per channel
Joe Friedchicken
NI Configuration Based Software Get with your fellow OS users
[ Linux ] [ macOS ]Principal Software Engineer :: Configuration Based Software
Senior Software Engineer :: Multifunction Instruments Applications Group (until May 2018)
Software Engineer :: Measurements RLP Group (until Mar 2014)
Applications Engineer :: High Speed Product Group (until Sep 2008)
10-08-2010 03:15 AM
Here are the results. In short : it does not work. But may be I have made a mistake ?
Here is the code I am running (on a Macbook Pro, with Suse 11.2):
// Channel parameters char chan[] = "Dev1/ai0, Dev1/ai1, Dev1/ai2, Dev1/ai3"; float64 min = -5.0; float64 max = 5.0; // Timing parameters char clockSource[] = "OnboardClock"; uInt64 samplesPerChan = 0;// = The number of samples to acquire for each channel in the task if sampleMode is DAQmx_Val_FiniteSamps
float64 sampleRate = 51200.0;
// Data read parameters #define bufferSize (uInt32)512 float64 data[bufferSize * 4]; int32 pointsToRead = bufferSize; int32 pointsRead; float64 timeout = 10.0; int32 totalRead = 0; printf("Press Ctrl-C to exit\n"); DAQmxErrChk (DAQmxBaseResetDevice("Dev1")); DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle)); DAQmxErrChk (DAQmxBaseCreateAIVoltageChan(taskHandle,chan,"",DAQmx_Val_Cfg_Default,min,max,DAQmx_Val_Volts,NULL)); DAQmxErrChk (DAQmxBaseCfgSampClkTiming(taskHandle,clockSource,sampleRate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,samplesPerChan)); DAQmxErrChk (DAQmxBaseCfgInputBuffer(taskHandle,2000000)); //use a 100,000 sample DMA buffer DAQmxErrChk (DAQmxBaseStartTask(taskHandle)); // The loop will quit after 10 seconds startTime = time(NULL); while( time(NULL)<startTime+30 ) { DAQmxErrChk (DAQmxBaseReadAnalogF64(taskHandle,pointsToRead,timeout,DAQmx_Val_GroupByScanNumber,data,bufferSize*4,&pointsRead,NULL)); totalRead += pointsRead; compteur++; printf("(%i) : Acquired %ld samples. Total %ld\n",compteur,pointsRead,totalRead); } printf("\nAcquired %ld total samples.\n",totalRead);
It is basically the C example you provided in contAcquireNChan.c
I have tried different values for the buffersize variable (corresponding to the numSampsPerChan parameter), including 512, 256 (corresponding to 8KiB and 4KiB read size), and smaller ones, with no success. Indeed, I get after a few acquisitions :
/usr/local/natinst/nidaqmxbase/examples/ai> ./contAcquireNChan Press Ctrl-C to exit (1) : Acquired 2048 samples. Total 2048 (2) : Acquired 2048 samples. Total 4096 (3) : Acquired 2048 samples. Total 6144 (4) : Acquired 2048 samples. Total 8192 (5) : Acquired 2048 samples. Total 10240 DAQmxBase Error -200361: <err>Onboard device memory overflow. Because of system and/or bus-bandwidth limitations, the driver could not read data from the device fast enough to keep up with the device throughput. Reduce the sample rate, or reduce the number of programs your computer is executing concurrently.
As you can see, I can only read about 10240 samples, and sometimes I get the error message at the very first reading operation.
10-08-2010 08:04 AM
Yes, everything looks good in your program. Setting samplesPerChan to 0 can be dangerous for a continuous measurement, since the driver uses that value to determine the size of the host's data buffer, but you explicitly set it with DAQmxBaseCfgInputBuffer().
The 9162 USB sleeve has a FIFO in it that helps alleviate USB latency, but in this case, the host is unable to ask it for data quickly enough. Even if the 9162's FIFO were larger, the computer would still fall behind and eventually the FIFO would become full and the device would throw this error.
I've created a bug report for this problem. While there may not be a bug, it's at least something we can investigate. In future DAQmx Base releases, look for CAR ID 252918 in the readme.
Joe Friedchicken
NI Configuration Based Software Get with your fellow OS users
[ Linux ] [ macOS ]Principal Software Engineer :: Configuration Based Software
Senior Software Engineer :: Multifunction Instruments Applications Group (until May 2018)
Software Engineer :: Measurements RLP Group (until Mar 2014)
Applications Engineer :: High Speed Product Group (until Sep 2008)
10-08-2010 08:12 AM
Thank you JoeFriedchicken for your help and the "bug" report.
In the meantime, I will try another laptop (not from Apple this time), hoping to find a working hardware/software combination.