09-12-2005 04:42 PM
{
double nNumberOfPoints = 65536.0;
double nSampleRate = 1000000.0;
// Convert and Normalize the Data Byte[] to a Double[]
double[] oYData = new double[nNumberOfPoints]; for(Int32 nIndex = 0; nIndex < nNumberOfPoints; nIndex++){
oYData[nIndex] = System.Convert.ToDouble(oDataArray[nIndex]) / System.Convert.ToDouble(System.Byte.MaxValue);
}
// Set the X Delta to milliseconds double nDeltaX = (1.0 / nSampleRate) * 1000.0; // Plot the Data Double[] this._oGraph.PlotY(oYData, 0.0, nDeltaX); // Change the X-Axis range of the Time Domain this._oXAxis.Range = new NationalInstruments.UI.Range(0.0, (nDeltaX * nNumberOfPoints)); // 0.0 to 65.536 milliseconds // Change the Y-Axis range of the Time Domain this._oYAxis.Range = new NationalInstruments.UI.Range(0.0, 1.0); // Always Normalized // Set an initial zoom for the user, he needs to be able to zoom out from this point if he wants to. // ZoomX into the first 10 milliseconds of data. this._oGraph.ZoomXY(this._oTimeDomainPlot, 0.0, 0.0, 10.0, 1.0); // <--*** This never works ***}
09-13-2005 01:17 PM
09-13-2005 01:27 PM
09-13-2005 02:01 PM
This code segment works in Mesaurement Studio 7.1, but as far as 7.0 it does not.
The ZoomXY never works on the screen, but it does raise the Zoom Event.
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using NationalInstruments;
using NationalInstruments.UI;
using NationalInstruemtns.UI.WaveformGraph;
namespace TestWaveformGraph
{
public class Form1 : System.Windows.Forms.Form
{
private Container _oComponents = null;
private WaveformGraph _oGraph = null;
private XAxis _oXAxis = null;
private YAxis _oYAxis = null;
private WaveformPlot _oPlot = null;
public Form1()
{
InitializeComponent();
double nFrequency = 5;
int nNumberOfPoints = 65536;
int nSampleRate = 1000000;
PlotData(CreateTestData(nNumberOfPoints, nFrequency), nSampleRate);
}
[STAThread]
static void Main()
{
Form1 oMainForm;
oMainForm = new Form1();
Application.Run(oMainForm);
}
protected override void Dispose(bool bDisposing)
{
if(bDisposing)
{
if(this._oComponents != null)
{
this._oComponents.Dispose();
}
}
base.Dispose(bDisposing);
}
#endregion
private void InitializeComponent()
{
this._oGraph = new WaveformGraph();
this._oPlot = new WaveformPlot();
this._oXAxis = new XAxis();
this._oYAxis = new YAxis();
((ISupportInitialize)(this._oGraph)).BeginInit();
this.SuspendLayout();
// _oGraph
this._oGraph.Caption = "Time Domain";
this._oGraph.Dock = DockStyle.Fill;
this._oGraph.InteractionMode = GraphInteractionModes.DragCursor;
this._oGraph.Location = new Point(0, 0);
this._oGraph.Name = "_oGraph";
this._oGraph.Plots.Add(this._oPlot);
this._oGraph.Size = new Size(648, 366);
this._oGraph.TabIndex = 0;
this._oGraph.XAxes.Add(this._oXAxis);
this._oGraph.YAxes.Add(this._oYAxis);
// _oPlot
this._oPlot.XAxis = this._oXAxis;
this._oPlot.YAxis = this._oYAxis;
// _oXAxis
this._oXAxis.Caption = "Time (milliseconds)";
// _oYAxis
this._oYAxis.Caption = "Amplitude (Normalized)";
// Form1
this.AutoScaleBaseSize = new Size(5, 13);
this.ClientSize = new System.Drawing.Size(648, 366);
this.Controls.Add(this._oGraph);
this.Name = "Form1";
this.Text = "Form1";
((ISupportInitialize)(this._oGraph)).EndInit();
this.ResumeLayout(false);
}
private Byte[] CreateTestData(int nNumberOfPoints, double nFrequency)
{
double nAmplitude = .5;
double nOffset = .5;
double nPi = System.Math.PI;
double nPoints = Convert.ToDouble(nNumberOfPoints);
byte[] oDataArray = new byte[nNumberOfPoints];
for(int nIndex = 0; nIndex < oDataArray.Length; nIndex++)
{
double nY = nOffset + nAmplitude * Math.Sin(nFrequency * Convert.ToDouble(nIndex) * 2.0 * nPi / nPoints);
oDataArray[nIndex] = Convert.ToByte(nY * Convert.ToDouble(Byte.MaxValue));
}
return oDataArray;
}
private void PlotData(byte[] oDataArray, int nSampleRate)
{
double[] oYData = new double[oDataArray.Length];
for(int nIndex = 0; nIndex < oDataArray.Length; nIndex++)
{
oYData[nIndex] = Convert.ToDouble(oDataArray[nIndex]) / Convert.ToDouble(Byte.MaxValue);
}
double nDeltaX = (1.0 / Convert.ToDouble(nSampleRate)) * 1000.0;
this._oPlot.PlotY(oYData, 0.0, nDeltaX);
this._oXAxis.Range = new Range(0.0, (nDeltaX * Convert.ToDouble(oDataArray.Length)));
this._oYAxis.Range = new Range(0.0, 1.0);
//************* The next line does not work in Measurement Studio 7.0, but works in 7.1 ***************
this._oGraph.ZoomXY(this._oPlot, this._oXAxis.Range.Minimum, this._oYAxis.Range.Minimum, (this._oXAxis.Range.Maximum / 4.0), this._oYAxis.Range.Maximum);
}
#endregion
}
}