Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

MultipleAcquisitionAverage

Hi,

 

I have a NI 5105 digitizer, and want to do multi channel (8), multi record (4), data acquisition and get an average from the multi-recording. I tried to run your sample c# program : AdvancedMeasurementLibrary and set

 

Channel Name to: 0,1,2,3,4,5,6,7

Timeout: 50

Processing Step: MultipleAcquisitionAverage

Array Measurement: MultipleAcquisitionAverage

 

 The following msg occured when I ran the application:

 

Error BFFA4033.

Possible Reasons:  The fetch parameters are not valid.

 

Please help me to fix the problem.

 

Thanks

 

0 Kudos
Message 1 of 9
(4,452 Views)

Hi LinaL,

 

I was able to run the Advanced Measurement Library .NET 3.5 example on a NI PCI-5105.

 

I ran it on the following system.

Windows 7 32-bit

NI-SCOPE 3.8

PCI-5105

Visual Studio 2008 and .NET 3.5

NI.SCOPE.NET Class Library 1.1.1

CH0,1: Analog voltage signal from a multifunction DAQ card

 

Parameters:

Array Measurement: MultipleAcquisitionAverage

Channel Name to: 0,1

Timeout: 50

Processing Step: MultipleAcquisitionAverage

Default Filter Parameters

 

This ran on my machine without any errors. Do you mind listing what is different about your machine than mine including drivers, system specifications, or parameters?

 

Thanks,

Aaron

 

National Instruments
0 Kudos
Message 2 of 9
(4,441 Views)

Thanks, Aaron,

 

My system is as the following:

 

 

Windows 7 32-bit

NI-SCOPE 3.6

PCI-5105

Visual Studio 2008 and .NET 3.5

 

The trigger we used is digitalEdge, so I modified the program and set:

 

sampleScopeSession.Triggers.Reference.Type = ScopeReferenceTriggerType.DigitalEdge; 

 sampleScopeSession.Triggers.Reference.Source = "VAL_PFI_1";

 

I still get the same error message.

 

0 Kudos
Message 3 of 9
(4,432 Views)

LinaL,

 

Where did you place the trigger configuration? To add a digital trigger to the program, do the following:

 

Below this line in the acquireButton_Click(object sender, EventArgs e)method:

sampleScopeSession.Channels[channelTextBox.Text].Enabled = true;

 

Place these two lines:

sampleScopeSession.Triggers.Reference.Type = ScopeReferenceTriggerType.DigitalEdge; sampleScopeSession.Triggers.Reference.Source = "/PCI-5105/PFI1";

 

The key is that the device and line must be correct. It should be "/theDeviceName/theLineName". You can find the device name by open Measurement & Automation Explorer and looking at your device (Start » All Programs » National Instruments). If you are using a digital trigger connected to the external trigger PFI line, then the line should be PFI1.

 

Regards,

Aaron

National Instruments
0 Kudos
Message 4 of 9
(4,420 Views)

I only changed two lines of your sample codes. The function looks like this after my change:

============================================================================

 

       private void acquireButton_Click(object sender, EventArgs e)        {            errorTextBox.Clear();            acquireButton.Enabled = false;            setUpSampleDataGrid = false;            setUpMeasurementsDataGrid = false;            sampleLastCount = 0;            measurementsLastCount = 0;            try            {                sampleScopeSession.ResourceDescriptor = resourceNameComboBox.Text;                sampleScopeSession.Open();                ScopeMultipleRecordMeasurementReader measurementReader = null;                sampleScopeSession.Channels[channelTextBox.Text].Enabled = true;                sampleDataTable = new DataTable("Sampled Waveform");                sampleDataSet = new DataSet();                sampleDataSet.Tables.Add(sampleDataTable);                sampledDataDataGrid.SetDataBinding(sampleDataSet, "Sampled Waveform");                measurementsDataTable = new DataTable("Measurements");                measurementsDataSet = new DataSet();                measurementsDataSet.Tables.Add(measurementsDataTable);                measurementDataDataGrid.SetDataBinding(measurementsDataSet, "Measurements");                sampleScopeSession.Triggers.Reference.Type = ScopeReferenceTriggerType.DigitalEdge;  // my Change                sampleScopeSession.Triggers.Reference.Source = "VAL_PFI_1";     //my change                stop = false;                while (!stop)                {                    sampleScopeSession.Acquisition.Initiate();
                    sampleScopeSession.Channels[channelTextBox.Text].Measurements.Filter.Type = (ScopeMeasurementFilterType)filterComboBox.SelectedItem;                    sampleScopeSession.Channels[channelTextBox.Text].Measurements.Filter.CutoffFrequency = double.Parse(passFrequencyTextBox.Text);                    sampleScopeSession.Channels[channelTextBox.Text].Measurements.Filter.CenterFrequency = double.Parse(stopFrequencyTextBox.Text);                    sampleScopeSession.Channels[channelTextBox.Text].Measurements.Filter.Width = double.Parse(widthTextBox.Text);                    sampleScopeSession.Channels[channelTextBox.Text].Measurements.AddWaveformProcessing((ScopeArrayMeasurementType)processingStepComboBox.SelectedItem);
                    measurementReader = new ScopeMultipleRecordMeasurementReader(sampleScopeSession);

                    ScopeMultipleRecordReader reader = new ScopeMultipleRecordReader(sampleScopeSession);
                 //   originalWaveforms = reader.MemoryOptimizedFetchFromMultipleChannels(channelTextBox.Text, 0, 1, 1000, PrecisionTimeSpan.FromSeconds(5), originalWaveforms);                       originalWaveforms = reader.MemoryOptimizedFetchFromMultipleChannels(channelTextBox.Text, 0, 2, 10, PrecisionTimeSpan.FromSeconds(5), originalWaveforms);
                    measurementWaveforms = measurementReader.MemoryOptimizedFetchArrayMeasurementFromMultipleChannels(channelTextBox.Text, 0, 1, 1000, (ScopeArrayMeasurementType)arrayMeasurementComboBox.SelectedItem, PrecisionTimeSpan.FromSeconds(5), measurementWaveforms);
                    PlotRecords(sampledDataDataGrid, sampleDataTable, originalWaveforms, ref setUpSampleDataGrid, ref sampleLastCount);                    PlotRecords(measurementDataDataGrid, measurementsDataTable, measurementWaveforms, ref setUpMeasurementsDataGrid, ref measurementsLastCount);                                        Application.DoEvents();                }                sampleScopeSession.Channels[channelTextBox.Text].Measurements.ClearWaveformProcessing();            }            catch (Exception ex)            {                errorTextBox.Text = ex.Message;                stop = true;            }            if

(stop)            {                Stopped();            }        }

 

 

======================================================

the following two lines I added worked for your other .net samples programs:

 

  sampleScopeSession.Triggers.Reference.Type = ScopeReferenceTriggerType.DigitalEdge;              sampleScopeSession.Triggers.Reference.Source = "VAL_PFI_1";

0 Kudos
Message 5 of 9
(4,408 Views)

Hi Aaron,

 

I have found the problem. After I set:

 

sampleScopeSession.Timing.NumberOfRecordsToAcquire = 2;

 

the program runs without problems.

 

 

Now my questions is: would you recommend a good and fast  approach for my apprication that has the following requirements:

 

1. multiple channel data acquisition;

 

2.  multiple records for each channel, (such as: triggering  4 times to get  4 records for each channel: wave1, wave2, wave3,wave4)

 

3. get average of the multiple records for each channel : : averageWave = ( wave1 + wave2 + wave3 + wave4) / 4

 

Does Measurement Studio have a function  that I can call directly to get  the averaging values of multiple records?

 

Thanks

 

 

 

0 Kudos
Message 6 of 9
(4,399 Views)

LinaL,

 

I'm glad that you got it working. You will be able to do questions 1, 2 using the NI-SCOPE .NET library functions. You don't even need Measurement Studio to create a multiple record, multiple channel acquisition. The MultiRecord example would be a good starting point.

 

As for question 3 about the averages: You will have to program this function yourself but it should be fairly straight forward. Throughout you're acquisition loop, you will have to collect the record data using a List or Array and then perform you're post-process averaging. Here is the basic idea in psuedocode:

 

Acquisition Loop - Initialize the Lists and add each new record to the list during acquisition:

 

List wave1

List wave2

List wave3

List wave4

while acquiring data:

  wave1.Add(new record)

  wave2.Add(new record)

  wave3.Add(new record)

  wave4.Add(new record)

 

Average Method - Initialize the average List and calculate the average of the waveforms.


List waveAverage

Average(wave1, wave2, wave3, wave4)

  for x=0; x < wave1.Count; x++

    waveAverage.Add((wave1[x] + wave2[x] + wave3[x] + wave4[x]) / 4)

 

 Regards,

Aaron

National Instruments
0 Kudos
Message 7 of 9
(4,380 Views)

 Thank you very much, Aaron,

 

Would you please tell me what the following function is for and what the output is?

 

========================                    

int numRecord = 4;

int numSamp = 2000;

  measurementWaveforms = sampleScopeMultipleRecordMeasurementReader.MemoryOptimizedFetchArrayMeasurementFromMultipleChannels("0,1,3", 0, numRecord, numSamp, ScopeArrayMeasurementType.MultipleAcquisitionAverage, PrecisionTimeSpan.FromSeconds(5), measurementWaveforms);

0 Kudos
Message 8 of 9
(4,370 Views)

LinaL,

 

The description for the MultipleAcquisitionAverage function:

 

The first time this measurement is called after it is cleared, an array the same size as the input is initialized to the input waveform, and the initial x and x increment values are set. Every subsequent call updates and returns the running average array without affecting the size of the array. The average array is cleared by calling niScope Clear Waveform Measurement Stats VI or the niScope_ClearWaveformMeasurementStats with the measurement function parameter set to Multi Acq Average.

 

This description is located in the NI High-Speed Digitizers Help in Start Menu » National Instruments » NI-SCOPE » Documentation. This is the best resource for information about library functions. The C function prototypes usually map pretty well to their .NET equivalents.

 

Regards,

Aaron 

 

 

National Instruments
0 Kudos
Message 9 of 9
(4,363 Views)