Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

write cannot be porformed because number of channels in the data does not match number of channels in the task

Solved!
Go to solution

hello,

 

i'm trying to write analogs from buffer to several channels using NI-6723.

For some reason, everytime I pass to function double buffer (1D) that holds buffers for all channels,

i always end up with excpetion saying the numbers of channels in the data is "1".

 

i'm using c#:

Task m_TaskHandle = new Task(); string sChannelsList = "Dev2/ao21:23"; m_TaskHandle.AOChannels.CreateVoltageChannel( sChannelsList, "", 0, 5, AOVoltageUnits.Volts ); int iNumberOfSamples = 4; double dSamplingFrequency = 1000; m_TaskHandle.Timing.ConfigureSampleClock("", dSamplingFrequency, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, iNumberOfSamples /* Only relevant if mode is FiniteSamples */); // Data code is here

double[] adSampleBuffer;

// array values removed from this code snippet (here i have function that generates data)

// array size is: num_of_samples * total_channels (in this case 4 * 3) AnalogSingleChannelWriter ChanWriter = new AnalogSingleChannelWriter(m_TaskHandle.Stream); ChanWriter.WriteMultiSample(false, adSampleBuffer); m_TaskHandle.Start();

 

 

 

Not sure what am i missing, how does the MSTDIO determine the "number of channels in data", as i keep getting in exception it's always equals to 1.

 

would appricate any help.

thanks.

0 Kudos
Message 1 of 3
(3,908 Views)
Solution
Accepted by topic author idanbis

Hi idanbis,

 

As for the code snippet you posted, you are creating more than one channel by using the range ao21:23. Given this, you should be using AnalogMultiChannelWriter to setup your writing operation instead of AnalogSingleChannelWriter.

 

In order to write using AnalogMultiChannelWriter::WriteMultiSample(boolean, double[,]), you should know that the data you want to write should be stored in a 2D array. Each element in the first dimension of this array corresponds to a channel in the task, while each element in the second dimension, corresponds to a sample to write to its corresponding channel. For instance, let:

 

double  [,]  data = new double[numChannels, numSamplesPerChannel];

 

Then:

 

data[0,0...numSamplesPerChannel]; // This is the set of all the samples in the first channel (ao21 in your code).

 

I hope this was helpful. Let me know if I left doubts remaining.

 

Best regards,

Anzurio

Message 2 of 3
(3,900 Views)

That solved it.

Thank you for the fast reply. Smiley Happy

0 Kudos
Message 3 of 3
(3,896 Views)