11-09-2009 02:29 AM
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.
Solved! Go to Solution.
11-09-2009 10:47 AM
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
11-09-2009 10:55 AM
That solved it.
Thank you for the fast reply.