Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxReadDigitalLines - Ignoring Properties at Higher Sample Count

I can successfully read 4 digital input devices, in the same task, when reading 1 sample per channel.  However, I get unexpected results if I try to sample more than 1 (e.g. 10 samples per channel).

 

I am using 4 digital input devies, 9425, installed on the cDAQ 9178 chassis.  All devices are assigned to the same task.

 

 

DAQmxCreateDIChan(taskHandle, physicalChannelString1, channelNameString1, DAQmx_Val_ChanForAllLines);
......
DAQmxCreateDIChan(taskHandle, physicalChannelString4, channelNameString4, DAQmx_Val_ChanForAllLines);

 

 

I then continually read from the devices in my update loop:

 

totalSamples = 10 * MAX_CHANNELS * 4; // MAX_CHANNELS = 32

DAQmxReadDigitalLines(
taskHandle, 10, timeout, DAQmx_Val_GroupByScanNumber, &dataVector[0],
totalSamples, &numSamplesRead, &bytesPerSample, NULL);

 

 

However, instead of creating one channel for all lines, as stated by DAQmx_Val_ChanForAllLines when creating the channel, it creates a channel for each line.  And oddly enough it bases the order on the number of channels in the first device added to the task and not the full max channels.  For example, the first device states only 31 lines when creating the digital channel for the task, so the data array is separated in 31 increments between each device.

 

I'm also using DAQmx_Val_GroupByScanNumber for interleaving because it seems to ignore the non-interleaved setting: DAQmx_Val_GroupByChannel.

 

I am very confused as to why it's ignoring those properties.  My only hypothesis is that it's not set at a high enough sample rate or the buffer size is too small.  I'm using the default rate at 1000 S/s and buffer size at 10kS (How is the DAQmx Buffer Size Allocated).

 

Am I missing a configuration?

0 Kudos
Message 1 of 3
(2,554 Views)
If you try to sample at 10 samples/channel in a task with channels from a single module, do you see the same behavior? 
 
What happens if you set the numSampsPerChan parameter in the DAQmxReadDigitalLines() function to -1 (read all available samples, assuming continuous sampling)?
 
 
Quentin
Applications Engineer
National Instruments
0 Kudos
Message 2 of 3
(2,456 Views)

In regards to your question with using 10 samples for a single device, the result is that it reads all 32 channels, which would be expected for the DAQmx_Val_ChanForAllLines property.  It only seems to ignore this when having more than one device in the task.

 

I was eventually able to get this working.  Here's my code:

 

 

totalSamples = 10 * MAX_CHANNELS * 4; // MAX_CHANNELS = 32

// The data array is still filled in an interleaved pattern
// even though I set it to GroupByChannel DAQmxReadDigitalLines( taskHandle, 10, timeout, DAQmx_Val_GroupByChannel, &dataVector[0], totalSamples, &numSamplesRead, &bytesPerSample, NULL); int startIdx = 0; int endIdx = 0; for (int i = 0; i < deviceVector.size(); i++) { // Data array consists of all devices so it needs to be split up into // portions with each one belonging to a specific device startIdx = endIdx; endIdx = startIdx + (bytesPerSample * numSamplesRead); // Go through data array for current device for (int j = startIdx; j < endIdx; j++) { dataVector[j].... } }

 

Although the end result is what I wanted to achieve, I am still confused as to why these properties are ignored.  Is this a bug or am I missing something?

 

The issues I found were:

- It does not create a channel for all lines when using the DAQmx_CreateChanForAllLines property when creating the virtual channel for a device.  Instead, it will create a number equal to the device that has the highest number of channels.

 

- Data array is interleaved when calling DAQmxReadDigitalLines, even when using the DAQmx_Val_GroupByChanNumber.  Could it be that this property is setting the number of devices found in a non-interleaved pattern but the data within each device is interleaved?

 

These issues only occured when adding multiple devices to the same task and having a sample count higher than 1.

0 Kudos
Message 3 of 3
(2,427 Views)