Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Waveform Graph Panning Error

I have a simple test app built off the NI example.  I changed the X-axis to DateTime format.
Panning works as expected-- allowing free access to ranges not on the original plot.  However, when I add actual data to the plot,  it throws an app killing error when I try to pan below the X=0 point.
 
The error is coming out of the graph component, so I can't see a way to catch it.
Any ideas on how to prevent this -- or at least trap it?
 
Tom
0 Kudos
Message 1 of 5
(4,101 Views)
Hi Tom,

Could you post your program?

Regards,
0 Kudos
Message 2 of 5
(4,079 Views)

Its all in this Main Form. (Is there a way to put attachments in this forum?  Otherwise, here's the text dump).

Run btnGetData for a few points. Stop it and try to pan X<0. Crashes on me everytime (Windows XP sp2. VS2003).

Tom

 

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

// Add reference to NationalInstruments.Analysis.Professional

using NationalInstruments.Analysis.SignalGeneration;

using NationalInstruments;

using NationalInstruments.UI;

using NationalInstruments.UI.WindowsForms;

namespace BurnIn_Plot

{

public class BurnIn_Plot_Form : System.Windows.Forms.Form

{

#region Windows Form Designer generated code

   [I removed this stuff to save space]

#region Member variables

private NationalInstruments.UI.WindowsForms.WaveformGraph waveformGraph1;

private NationalInstruments.UI.XAxis xAxisForm;

private NationalInstruments.UI.YAxis yAxisForm;

private System.Windows.Forms.Button btnGetData;

private System.Timers.Timer simulateTimer;

private System.Windows.Forms.Button btnStopData;

private NationalInstruments.UI.WaveformPlot SineWavePlot;

private NationalInstruments.UI.WaveformPlot ScrollingSineWavePlot;

private System.Windows.Forms.TextBox textBox1;

private const int NUM_PTS=50;

private double[] WaveData;

private static int count=0;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

#endregion

#region Constructor

public BurnIn_Plot_Form()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

// Set up waveform plots to hold the plotting data

SineWavePlot.LineColor = System.Drawing.Color.Black;

SineWavePlot.XAxis = this.xAxisForm;

SineWavePlot.YAxis = this.yAxisForm;

InitializePlot();

}

private void InitializePlot()

{

// Initialize XAxis of Plots -- both use the same one.

DateTime startTime= System.DateTime.Today; //DateTime.Now; // Hold for plotting data

xAxisForm.Mode=AxisMode.StripChart;

xAxisForm.MajorDivisions.LabelFormat= new NationalInstruments.UI.FormatString(

NationalInstruments.UI.FormatStringMode.DateTime,"HH:mm:ss");

xAxisForm.MajorDivisions.GridVisible=true; xAxisForm.MajorDivisions.GridColor= Color.Gray;

yAxisForm.MajorDivisions.GridVisible=true; yAxisForm.MajorDivisions.GridColor= Color.Gray;

xAxisForm.Range=new Range(startTime,TimeSpan.FromSeconds(300));

xAxisForm.MajorDivisions.Interval = 60;

yAxisForm.Range=new Range(-10,10);

yAxisForm.MajorDivisions.Interval = 2;

xAxisForm.AutoSpacing=false;

yAxisForm.AutoSpacing=false;

 

}

private void BurnIn_Plot_Form_Load(object sender, System.EventArgs e)

{

btnGetData.Enabled=true;

btnStopData.Enabled=false;

}

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

 

#endregion

 

 

 

#region PlotData Methods

private void btnGetData_Click(object sender, System.EventArgs e)

{

btnGetData.Enabled=false;

btnStopData.Enabled=true;

count=0;

WaveData = AcquireData(2, 6, 0, NUM_PTS, 0.25);

simulateTimer.Interval= 500;

simulateTimer.Enabled= true;

simulateTimer.Start();

}

private void simulateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)

{

if(count<NUM_PTS)

{

SineWavePlot.PlotYAppend(WaveData[count],5.0);

textBox1.Text =Convert.ToString( count++);

Application.DoEvents();

}

else

{

simulateTimer.Stop();

btnGetData.Enabled=true;

btnStopData.Enabled=false;

}

}

private double[] AcquireData(double frequency, double amplitude, double phase, double numberSamples, double noiseAmplitude)

{

SineSignal sineSignal = new SineSignal(frequency, amplitude, phase);

WhiteNoiseSignal noise = new WhiteNoiseSignal(noiseAmplitude);

SignalGenerator generator = new SignalGenerator(numberSamples, (long)numberSamples);

generator.Signals.Add(sineSignal);

generator.Signals.Add(noise);

return generator.Generate();

}

private void btnStopData_Click(object sender, System.EventArgs e)

{

simulateTimer.Stop();

btnGetData.Enabled=true;

btnStopData.Enabled=false;

}

#endregion

 

 

} // end class

} // end namespace

 

 

0 Kudos
Message 3 of 5
(4,078 Views)
Duh. That would be the "attachment box" down there.
 
Here's the project:
0 Kudos
Message 4 of 5
(4,066 Views)
Hi Tom,

Based on this discussion forum (Restrict Pan-Mode), I try adding the following lines to your program:

        waveformGraph1.XAxisRangeChanged += new XAxisEventHandler(waveformGraph1_XAxisRangeChanged);

        void waveformGraph1_XAxisRangeChanged(object sender, XAxisEventArgs e)
        {
            if (e.XAxis.Range.Minimum < 0)
            {
                xAxisForm.Range = new Range(startTime, TimeSpan.FromSeconds(300));
            }
        }


This will avoid the exception, and after speaking with R&D, this seems to be the best way available.

Regards,
0 Kudos
Message 5 of 5
(4,053 Views)