Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Error -200229, buffer too small in timed digital read

I am trying to do a buffered, timed read on the DIO lines on PCI-6229. I am working in C++ using VC++.net.

I greatly appreciate your help- this is a lot of stuff to read through!

I set up the read this way (just the DAQmx lines included):

string lines = "/pci6229/port0/line0:1";
if (NIerror = DAQmxCreateTask(taskname.str().c_str(), &h))
if (NIerror = DAQmxCreateDIChan(h, lines.c_str(), NULL, grouping)) // grouping set to DAQmx_Val_ChanPerLine
if (NIerror = DAQmxCfgSampClkTiming(h, clockSource.c_str(), clockRate, clockEdge , DAQmx_Val_FiniteSamps, numSamples))

clockSource is "/pci6229/ctr0internaloutput"
clockRate is 1.0 (but the counter is actually going at a rate of 10- is that a problem?)
clockEdge is 10171 (DAQmx_Val_Falling)
numSamples is 128

added to try to fix the problem:
if (NIerror = DAQmxCfgInputBuffer(h, numSamples*4))

if (NIerror = DAQmxStartTask(h))

Now I periodically use these calls to try to get the data:

uInt32 AvailableSamples;

int32 error = DAQmxGetReadAvailSampPerChan(GetTaskHandle(), &AvailableSamples);

if (AvailableSamples > 0)
{
uInt32 numChans;
error = DAQmxGetTaskNumChans(GetTaskHandle(), &numChans);

// vector readArray(AvailableSamples*numChans, 0); // first tried this
vector readArray(300*numChans, 0); // desperation attempt to try to make it work
int32 sampsPerChanRead;
int32 numBytesPerSamp;

int32 error = DAQmxReadDigitalLines(GetTaskHandle(), readArray.size(), timeout, DAQmx_Val_GroupByChannel, & readArray[0], readArray.size(), &sampsPerChanRead, &numBytesPerSamp, NULL);


This call to DAQmxReadDigitalLines always returns error -200229. I have tried to increase the size of every buffer I can identify. Is this operation simply not something that can be done?
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
www.wavemetrics.com
0 Kudos
Message 1 of 4
(4,249 Views)
Hello John,

You should be able to perform this operation.

"if (NIerror = DAQmxCfgInputBuffer(h, numSamples*4))"
I would leave this line out. DAQmx should create an input buffer automatically based on the number of channels and number of samples per channel.

I would also leave out the following section of code:
"uInt32 AvailableSamples;

int32 error = DAQmxGetReadAvailSampPerChan(GetTaskHandle(), &AvailableSamples);

if (AvailableSamples > 0)
{
uInt32 numChans;
error = DAQmxGetTaskNumChans(GetTaskHandle(), &numChans);

// vector readArray(AvailableSamples*numChans, 0); // first tried this
vector readArray(300*numChans, 0); // desperation attempt to try to make it work
int32 sampsPerChanRead;
int32 numBytesPerSamp;"

If you just call the DAQmxReadDigitalLines() function with "numSampsPerChan" set to -1, DAQmx will wait until all samples are acquired before performing the read.

If this does not help, please send me a small section of code that reproduces that behavior, and I will try running it on my machine.

Let me know your results,
Sean C.
0 Kudos
Message 2 of 4
(4,233 Views)
Sean:

Thank you very much for wading through my post.

>"if (NIerror = DAQmxCfgInputBuffer(h, numSamples*4))"
>I would leave this line out. DAQmx should create an input buffer automatically
>based on the number of channels and number of samples per channel.

Yeah- I put that in trying to fix the problem. The error message doesn't say *which* buffer is too small 🙂

>If you just call the DAQmxReadDigitalLines() function with "numSampsPerChan" set to -1,
>DAQmx will wait until all samples are acquired before performing the read.

I'm trying to avoid the wait. That's why I'm trying to figure out how many samples are ready.

I suppose I can try numSampsPerChan=-1, set a short timeout and check for the timeout error.

>If this does not help, please send me a small section of code that reproduces that behavior,
>and I will try running it on my machine.

I will try modifying one of the examples to do what I'm trying to do.

Again, Thank you!
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
www.wavemetrics.com
0 Kudos
Message 3 of 4
(4,230 Views)
I said:

>I will try modifying one of the examples to do what I'm trying to do.

and in the process I figured out what I was doing wrong!

The DAQmxReadDigitalLines() function isn't quite parallel to the DAQmxReadDigitalUxx() functions. ReadDigitalLines() takes a parameters for numSampsPerChan to specify how many samples to read, and an array size *in bytes*, not in samples. I was using the same number for both, whereas the array size needs to be multiplied by the number of channels in the task.

Again, thank you, Sean, for your efforts and willingness to claw through my posting.
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
www.wavemetrics.com
0 Kudos
Message 4 of 4
(4,210 Views)