06-22-2007 12:49 PM
06-25-2007 10:04 AM
06-25-2007 11:38 AM
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
06-25-2007 10:33 PM
06-26-2007 12:41 PM