01-30-2015 12:25 AM
Hi all,
I'm using an NI USB-6341 device to do a number of voltage and current measurements simultaneously. I'm copying the code below. I want to make it in a way that when the method is called I want the DAQ to take N number of samples and return a single result by averaging all the values. I want to do all this on the DAQ not on my application.
Do you think is there a way to make this happen becuase i did not succeed doing it yet.
public double[] makeMeasurement(string[] channel, string[] type, double[] minValue, double[] maxValue, double [] shuntRes) { results = new double[8]; try { using (Task task = new Task()) { int counter = 0; for (int i = 0; i < 8; i++) { if (channel[i] != null) { if (type[i] == "Voltage") { string channelName = "Dev1/ai" + i; //Turn on a channel, essentially task.AIChannels.CreateVoltageChannel(channelName, "", AITerminalConfiguration.Differential, minValue[i], maxValue[i], AIVoltageUnits.Volts); //AnalogMultiChannelReader reader = new AnalogMultiChannelReader(task.Stream); AnalogMultiChannelReader reader = new AnalogMultiChannelReader(task.Stream); //check that parameters are all good task.Control(TaskAction.Verify); double[] result = reader.ReadSingleSample(); results[i] = result[counter]; counter++; } else { string channelName = "Dev1/ai" + i; task.AIChannels.CreateCurrentChannel(channelName, "", AITerminalConfiguration.Differential, minValue[i], maxValue[i], shuntRes[i], AICurrentUnits.Amps); AnalogMultiChannelReader reader = new AnalogMultiChannelReader(task.Stream); //check that parameters are all good task.Control(TaskAction.Verify); double[] result = reader.ReadSingleSample(); results[i] = result[counter]; counter++; } } } } return results; }
02-02-2015 09:53 AM
Hi TCDD,
Unfortunatley, there is not a way to have the USB-6341 do on board averaging. You can only query the device for samples but you can not implement custom functionality on the device. Implementing the averaging in software would be a very small hit to performance. You can read multiple samples from a single channel, average and then store that value in the results output array.
02-03-2015 05:42 PM
Hi Frank,
Thanks for the tip. I think I will be using the multiple read function however there is something I would like to ask. Hope you can explain it becuase I'm a little bit confused.
task.Timing.ConfigureSampleClock("PFI0", 1000, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, 100);
The bit on the task.timing gets the number of samples and sampling frequency as the inputs for the function. So when I use this bit of code with a single read operation will the output be the last read value instead of the averaging of 100 samples sampled at 1kHz?
Thanks a lot for the help.
Taygun
02-04-2015 09:05 AM