Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Appending data to a cloned WaveformPlot result in NullReferenceException

Is there a formal place to report bugs? I have not found any Bug Report page, so I report it here.

 

Description/version:
If one append data to a cloned WaveformPlot object with WaveformPlot.PlotWaveformAppend<double>( ), one will get "NullReferenceException - Object reference not set to an instance of an object". The Measurement Studio version used is "Measurement Studio 2010 SP1" - version: 9.1.0.204. The Assembly version reported in the Help is "Assembly: NationalInstruments.UI (in NationalInstruments.UI.dll) Version: 9.1.35.204"

I got this error on Win 7 and Measurement Studio 2010. The problem did not appear on Win XP with Measurement Studio 2009 - Version 8.9.0.246. The code I got problem with was developed on the old version.

 

Steps to reproduce/workaround:

I have made an example which reproduce the problem and shows a workaround. It is appended together with a picture of the program result without the exception error. There is two ways to avoid NullReferenceException in my reproducing program:

- Set the cloneFlag = false
- define the WORKAROUND_INCLUDED symbol

The two methods does much the same, but in the last case one clone the plot and then rewrite the plot data.

 

Impact

I should like to see the problem solved within reasonable time as the code where the problem persist is used in critical phases of oil well intervention operations. An exception situation in such cases should be avoided.

 

My epost address is

gie@iris.no

 

 

Program result with no Exception

 

// 26.06.2012:
// Append data to a cloned plot result in NullReferenceException
// This example is a reconstruction of the problem
//
// 

//#define WORKAROUND_INCLUDED


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NationalInstruments;
using NationalInstruments.UI;
using NationalInstruments.UI.WindowsForms;




namespace VerifyWaveformPlotClone
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();


      DateTime now = DateTime.Now;

      // bool cloneFlag = false;
      bool cloneFlag = true;
   
      // --- Create graph 1 ---
      WaveformGraph graph1 = new WaveformGraph();
      this.Controls.Add( graph1 );
      graph1.Size = new System.Drawing.Size( 800, 200 );

      // --- Y-Axes setup ---
      YAxis yAxis1 = new YAxis();
      yAxis1.MajorDivisions.GridVisible = true;
      graph1.YAxes.Clear();
      graph1.YAxes.AddRange( new YAxis[] { yAxis1 } );

      // --- X-Axis setup ---
      XAxis xAxis1 = new XAxis();
      xAxis1.MajorDivisions.LabelFormat = new FormatString( FormatStringMode.DateTime, "HH:mm:ss" );
      xAxis1.MajorDivisions.GridVisible = true;
      xAxis1.Mode = AxisMode.StripChart;
      xAxis1.Range = new Range( now, TimeSpan.FromSeconds( 20 ) );
      graph1.XAxes.Clear();
      graph1.XAxes.AddRange( new XAxis[] { xAxis1 } );

      // --- Create Plot 1 ---
      WaveformPlot plot1 = new WaveformPlot(xAxis1, yAxis1);

      AnalogWaveformPlotOptions timePlotOpt = new AnalogWaveformPlotOptions(
        AnalogWaveformPlotDisplayMode.Time,   // Display in time
        AnalogWaveformPlotScaleMode.Scaled,   // Use scaled data, not raw data
        AnalogWaveformPlotTimingMode.Timing );// Use normal timing, not precision timing

      WaveformTiming waveTimingNow = WaveformTiming.CreateWithRegularInterval(
                               TimeSpan.FromMilliseconds( 1000.0 ), // Sample interval in milliseconds
                               now );    // Start of acquisition, DateTime

      
      AnalogWaveform<double> firstWaveAW1 = AnalogWaveform<double>.FromArray1D( new double[] { 0.0, 10.0, 0.0, 12.0 } );
      firstWaveAW1.Timing = waveTimingNow;

      plot1.PlotWaveform<double>( firstWaveAW1, timePlotOpt );
      graph1.Plots.Clear();
      graph1.Plots.Add( plot1 );
      
      
      
      // -------- Append data -------------

      double dt1;
      double yDummy;
      plot1.GetDataPoint( plot1.HistoryCount - 1, out dt1, out yDummy );

      AnalogWaveform<double> appWaveAW1 = AnalogWaveform<double>.FromArray1D( new double[] { 0.0, 5.0, 0.0, 6.0 } );
      appWaveAW1.Timing = WaveformTiming.CreateWithRegularInterval(
                               TimeSpan.FromMilliseconds( 1000.0 ), // Sample interval in milliseconds
                               DataConverter.Convert<DateTime>(dt1) + TimeSpan.FromMilliseconds( 1000.0 ) );

      plot1.PlotWaveformAppend<double>( appWaveAW1 );     // Appending data to a "not cloned" plot works fine







      // ------------------------------------------
      // ---- Clone -----
      // ------------------------------------------

      // --- Create graph 2 ---
      WaveformGraph graph2 = new WaveformGraph();
      this.Controls.Add( graph2 );
      graph2.Size = new System.Drawing.Size( 800, 200 );
      graph2.Location = new System.Drawing.Point( 0, 201 );

      // --- Y-Axes setup ---
      YAxis yAxis2 = new YAxis();
      yAxis2.MajorDivisions.GridVisible = true;
      graph2.YAxes.Clear();
      graph2.YAxes.AddRange( new YAxis[] { yAxis2 } );

      // --- X-Axis setup ---
      XAxis xAxis2 = new XAxis();
      xAxis2.MajorDivisions.LabelFormat = new FormatString( FormatStringMode.DateTime, "HH:mm:ss" );
      xAxis2.MajorDivisions.GridVisible = true;
      xAxis2.Mode = AxisMode.StripChart;
      xAxis2.Range = new Range( now, TimeSpan.FromSeconds( 20 ) );
      graph2.XAxes.Clear();
      graph2.XAxes.AddRange( new XAxis[] { xAxis2 } );




      WaveformPlot plot2;
      if( cloneFlag )
      {
        // This route will issue NullReferenceException
        plot2 = (WaveformPlot)plot1.Clone();
      }
      else
      {
        // This route will not issue NullReferenceException
        plot2 = new WaveformPlot( xAxis2, yAxis2 );
        AnalogWaveform<double> copyAW2 = AnalogWaveform<double>.FromArray1D( plot1.GetYData() );
        copyAW2.Timing = waveTimingNow;
        plot2.PlotWaveform<double>( copyAW2, timePlotOpt );
      }
      graph2.Plots.Clear();
      graph2.Plots.Add( plot2 );





      // -------- Append data -------------

      double dt2;
      plot2.GetDataPoint( plot2.HistoryCount - 1, out dt2, out yDummy );

      AnalogWaveform<double> appWaveAW2 = AnalogWaveform<double>.FromArray1D( new double[] { 0.0, 1.0, 0.0, 2.0 } );
      appWaveAW2.Timing = WaveformTiming.CreateWithRegularInterval(
                               TimeSpan.FromMilliseconds( 1000.0 ), // Sample interval in milliseconds
                               DataConverter.Convert<DateTime>( dt2 ) + TimeSpan.FromMilliseconds( 1000.0 ) );




#if WORKAROUND_INCLUDED
     //------------------------------------------------------
      //     --- Workaround ---
      //------------------------------------------------------
      // Skip the already done clone
      // Add the data once again (which was initially copied in the clone operation)
      AnalogWaveform<double> workaroundWaveAW2 = AnalogWaveform<double>.FromArray1D( plot1.GetYData() );
      workaroundWaveAW2.Timing = waveTimingNow;
      plot2.ClearData();
      plot2.PlotWaveform<double>( workaroundWaveAW2, timePlotOpt );
#endif //WORKAROUND_INCLUDED




      // --- Append operation ---
      plot2.PlotWaveformAppend<double>( appWaveAW2 );   // Appending data to the cloned plot issues NullReferenceException!

     
      
    }
  }
}

 

 

 

 

 

 

0 Kudos
Message 1 of 1
(4,454 Views)