10-21-2019 03:34 AM
Hey,
I'm using PCI6509 card to read out 100 000 samples per channel (I have 3 channels) but at the moment, with my code, I can read out maximum 150 samples/second which is too slow. I'm guessing that there is something missing from my code which is written in C.
Here is the code I'm using:
TaskHandle digitaskHandle=0;
uInt8 readArray[300000];
int32 sampsPerChanRead;
float64 timeout = 1.0;
DAQmxCreateTask("DigiRead", &digitaskHandle);
DAQmxCreateDIChan(digitaskHandle,"Dev2/port0", "X", DAQmx_Val_ChanForAllLines);
DAQmxCreateDIChan(digitaskHandle,"Dev2/port1", "Y", DAQmx_Val_ChanForAllLines);
DAQmxCreateDIChan(digitaskHandle,"Dev2/port2", "Z", DAQmx_Val_ChanForAllLines);
DAQmxCfgChangeDetectionTiming (digitaskHandle,"Dev2/port2/line4","", DAQmx_Val_FiniteSamps, 100000);
DAQmxStartTask(digitaskHandle);
uInt32 arraySizeInSamps;
arraySizeInSamps=300000;
DAQmxReadDigitalU8 (digitaskHandle, -1, timeout, DAQmx_Val_GroupByScanNumber, readArray, arraySizeInSamps, &sampsPerChanRead, NULL);
DAQmxStopTask(digitaskHandle);
DAQmxClearTask(digitaskHandle);
Please help, any suggestions are welcome.
10-21-2019
12:53 PM
- last edited on
09-19-2025
10:04 AM
by
Content Cleaner
I only program LabVIEW but your text code looks pretty straightforward to understand.
Your sample timing is based on change detection. Your sample rate will depend on how fast the configured digital changes occur. Presently, you appear to be configured to take samples only when there's a rising edge at port 2 line 4. What's the rate of rising edges there?
The PCI-6509 manual also states that the device notifies the system of changes via interrupt and that the change detection rate will be system dependent. (See pg 18). I'd be surprised if this limits you all the way down to 150 Samples/sec, but would also be surprised if the driver can handle 100000 interrupts/sec.
One more note on a different aspect of the code:
I assume the -1 value in the call to DAQmxReadDigitalU8() corresponds to an argument like '# of samples to read'. FYI, that value has a special meaning in a Finite Sampling task like yours. It means, "give me all the samples I configured the buffer for in my timing config call. If the task hasn't accumulated them yet, wait and block until it does (or until the timeout elapses, whichever comes first)."
Yours is a good use case for the -1 value. Just be aware that the behavior would be very different if you had a Continuous Sampling task. (Then it would mean, "return all the samples already in the buffer I didn't already retrieve on a prior read. Do not block or wait, even if you return 0 samples to me.")
-Kevin P