Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQ measurement averaging on device

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;
            }

 

0 Kudos
Message 1 of 4
(5,328 Views)

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.

Message 2 of 4
(5,286 Views)

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

 

0 Kudos
Message 3 of 4
(5,267 Views)
When you do a multiple sample read, you get all of the samples that you request. From this array, your code would need to find the mean. If you stick with the single sample read with the timing function for multiple samples, you will end up with a buffer overflow error since you will not be reading fast enough.
0 Kudos
Message 4 of 4
(5,249 Views)