D
dondigitech LaPel
Sorry about the code being hard to read, but I can assure you that it
did not look like that when I copied and pasted the message. I'm a
hardware engineer
who has only been using c# for a couple weeks now and must admit that
its been a long time since I've done any OO programming. But, all I want
to do is when the "Get Curves" button is clicked, for the event handler
to call the initializeIgnComm grabbing int[,] curveArray from my
CurveData class, and then use that data to plot. Thats all I want this
event handler to do. Get data, then plot it. Before messing with
delegates and event handlers and all
that this how I had my code. Of course I got the overloading error.
Ultimately the issue I am having is getting/passing the curveArray data
to the event handler.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO.Ports;
using System.Windows.Forms;
using System.Threading;
using PCComm;
using PortSet;
using ZedGraph;
namespace PCComm
{
public partial class frmMain : Form
{
CurveData comm = new CurveData();
string transType = string.Empty;
public frmMain()
{
InitializeComponent();
}
private void frmMain_Load(object sender, EventArgs e)
{
//SetDefaults();
}
# region MENU STRIP CONTROL
//<<<<<<<<< SERIAL PORT SETTINGS MENU >>>>>>>>>>//
private void settingsToolStripMenuItem_Click1(object sender,
EventArgs e)
{
// Make sure the port isn't already open
if (serialPort1.IsOpen)
{
MessageBox.Show("The port must be closed before changing
the settings.");
return;
}
else
{
// Create an instance of the settings form
PortSettings settings = new PortSettings();
if (settings.ShowDialog() == DialogResult.OK)
{
if (settings.selectedPort != "")
{
// Set the serial port to the new settings
serialPort1.PortName = settings.selectedPort;
serialPort1.BaudRate =
settings.selectedBaudrate;
showSettings();
}
else
{
MessageBox.Show("Error: Settings form returned
with no COM port selected.");
return; // bail out
}
}
else
{
MessageBox.Show("Error: buttonSetup_Click - Settings
dialog box did not return Okay.");
return; // bail out
}
// Open the port
try
{
serialPort1.Close();
serialPort1.Open();
menuStrip1.Items[1].Text = "Close Port";
showSettings();
}
catch (System.Exception ex)
{
MessageBox.Show("Error -
setupToolStripMenuItem_Click Exception: " + ex);
}
}
}
//<<<<<<<<< OPEN/CLOSE PORT BUTTON >>>>>>>>>>//
private void openPortToolStripMenuItem_Click(object sender,
EventArgs e)
{
try
{
if (serialPort1.IsOpen)
{
serialPort1.Close();
menuStrip1.Items[1].Text = "Open Port";
}
else
{
serialPort1.Open();
menuStrip1.Items[1].Text = "Close Port";
}
showSettings();
}
catch (System.Exception ex)
{
MessageBox.Show("Error - openPortToolStripMenuItem_Click
Exception: " + ex);
}
}
private void GroupBox1_Enter(object sender, EventArgs e)
{
}
//<<<<<<<<< GET CURVES BUTTON >>>>>>>>>>//
private void getCurvesToolStripMenuItem_Click(object sender,
EventArgs e, int[,] curveArray)
{
comm.DisplayWindow = rtbDisplay;
try
{
if (serialPort1.IsOpen)
{
comm.initializeIgnComm(serialPort1);
plotCurves(zedGraphControl1, curveArray);
}
else
{
MessageBox.Show("Error: COM port closed.");
return; // bail out
}
}
catch (System.Exception ex)
{
MessageBox.Show("Error - findIgnButton_Click Exception:
" + ex);
}
}
#endregion
# region CURVE ID HEADER
private void showSettings()
{
this.Text = "DYNATEK IGNITIONS - " +
serialPort1.PortName + " " +
serialPort1.BaudRate.ToString();
if (serialPort1.IsOpen)
{
this.Text += " - Port is open";
}
else
{
this.Text += " - Port is closed";
}
}
#endregion
# region GRAPH CURVES
private void zedGraphControl1_Load(object sender, EventArgs e)
{
}
private void plotCurves(ZedGraphControl zgc, int[,] curveArray)
{
GraphPane plotCurve = zgc.GraphPane; //Get a
reference to the GraphPane
// Set the Titles
plotCurve.Title.Text = "DFS726 IGNITION TIMING\n";
plotCurve.XAxis.Title.Text = "RPM(x100)";
plotCurve.YAxis.Title.Text = "Advance Angle(Degrees BTDC)";
PointPairList curve1 = new PointPairList(); //Create
curve1 list
sortData(curveArray); //Sort data into
list for plotting
LineItem ignCurve = plotCurve.AddCurve("WOT Curve 4",
curve1, Color.Red, SymbolType.Diamond);
zgc.AxisChange();
}
#endregion
//-------------------------------------------------
// SORT ARRAY DATA TO POINTS FUNCTION
//-------------------------------------------------
private PointPairList sortData(int[,] curveArray)
{
int numberOfCurves = 8;
int[,] advDegBTDC = new int[numberOfCurves,8];
int[,] rpmValues = new int[numberOfCurves,8];
int curveNumber = 0;
int arrayIndex = 0;
int genArrayIndex = 0;
// Copy data from rpmArray and advArray into rpmValues and
advDegBTDC arrays used for plots
for (curveNumber = 0; curveNumber < numberOfCurves;
curveNumber++)
{
for (arrayIndex = 0; arrayIndex < 8; arrayIndex++)
{
advDegBTDC[curveNumber,arrayIndex] =
curveArray[0,genArrayIndex];
rpmValues[curveNumber,arrayIndex] =
curveArray[1,genArrayIndex];
genArrayIndex++;
}
}
PointPairList list1 = new PointPairList();
// TEST: Just sending the first curve (8 data points) to
list1 to graph
for (int i = 0; i < 8; i++)
{
list1.Add(rpmValues[0,i], advDegBTDC[0,i]);
}
return list1;
}
}
}
did not look like that when I copied and pasted the message. I'm a
hardware engineer
who has only been using c# for a couple weeks now and must admit that
its been a long time since I've done any OO programming. But, all I want
to do is when the "Get Curves" button is clicked, for the event handler
to call the initializeIgnComm grabbing int[,] curveArray from my
CurveData class, and then use that data to plot. Thats all I want this
event handler to do. Get data, then plot it. Before messing with
delegates and event handlers and all
that this how I had my code. Of course I got the overloading error.
Ultimately the issue I am having is getting/passing the curveArray data
to the event handler.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO.Ports;
using System.Windows.Forms;
using System.Threading;
using PCComm;
using PortSet;
using ZedGraph;
namespace PCComm
{
public partial class frmMain : Form
{
CurveData comm = new CurveData();
string transType = string.Empty;
public frmMain()
{
InitializeComponent();
}
private void frmMain_Load(object sender, EventArgs e)
{
//SetDefaults();
}
# region MENU STRIP CONTROL
//<<<<<<<<< SERIAL PORT SETTINGS MENU >>>>>>>>>>//
private void settingsToolStripMenuItem_Click1(object sender,
EventArgs e)
{
// Make sure the port isn't already open
if (serialPort1.IsOpen)
{
MessageBox.Show("The port must be closed before changing
the settings.");
return;
}
else
{
// Create an instance of the settings form
PortSettings settings = new PortSettings();
if (settings.ShowDialog() == DialogResult.OK)
{
if (settings.selectedPort != "")
{
// Set the serial port to the new settings
serialPort1.PortName = settings.selectedPort;
serialPort1.BaudRate =
settings.selectedBaudrate;
showSettings();
}
else
{
MessageBox.Show("Error: Settings form returned
with no COM port selected.");
return; // bail out
}
}
else
{
MessageBox.Show("Error: buttonSetup_Click - Settings
dialog box did not return Okay.");
return; // bail out
}
// Open the port
try
{
serialPort1.Close();
serialPort1.Open();
menuStrip1.Items[1].Text = "Close Port";
showSettings();
}
catch (System.Exception ex)
{
MessageBox.Show("Error -
setupToolStripMenuItem_Click Exception: " + ex);
}
}
}
//<<<<<<<<< OPEN/CLOSE PORT BUTTON >>>>>>>>>>//
private void openPortToolStripMenuItem_Click(object sender,
EventArgs e)
{
try
{
if (serialPort1.IsOpen)
{
serialPort1.Close();
menuStrip1.Items[1].Text = "Open Port";
}
else
{
serialPort1.Open();
menuStrip1.Items[1].Text = "Close Port";
}
showSettings();
}
catch (System.Exception ex)
{
MessageBox.Show("Error - openPortToolStripMenuItem_Click
Exception: " + ex);
}
}
private void GroupBox1_Enter(object sender, EventArgs e)
{
}
//<<<<<<<<< GET CURVES BUTTON >>>>>>>>>>//
private void getCurvesToolStripMenuItem_Click(object sender,
EventArgs e, int[,] curveArray)
{
comm.DisplayWindow = rtbDisplay;
try
{
if (serialPort1.IsOpen)
{
comm.initializeIgnComm(serialPort1);
plotCurves(zedGraphControl1, curveArray);
}
else
{
MessageBox.Show("Error: COM port closed.");
return; // bail out
}
}
catch (System.Exception ex)
{
MessageBox.Show("Error - findIgnButton_Click Exception:
" + ex);
}
}
#endregion
# region CURVE ID HEADER
private void showSettings()
{
this.Text = "DYNATEK IGNITIONS - " +
serialPort1.PortName + " " +
serialPort1.BaudRate.ToString();
if (serialPort1.IsOpen)
{
this.Text += " - Port is open";
}
else
{
this.Text += " - Port is closed";
}
}
#endregion
# region GRAPH CURVES
private void zedGraphControl1_Load(object sender, EventArgs e)
{
}
private void plotCurves(ZedGraphControl zgc, int[,] curveArray)
{
GraphPane plotCurve = zgc.GraphPane; //Get a
reference to the GraphPane
// Set the Titles
plotCurve.Title.Text = "DFS726 IGNITION TIMING\n";
plotCurve.XAxis.Title.Text = "RPM(x100)";
plotCurve.YAxis.Title.Text = "Advance Angle(Degrees BTDC)";
PointPairList curve1 = new PointPairList(); //Create
curve1 list
sortData(curveArray); //Sort data into
list for plotting
LineItem ignCurve = plotCurve.AddCurve("WOT Curve 4",
curve1, Color.Red, SymbolType.Diamond);
zgc.AxisChange();
}
#endregion
//-------------------------------------------------
// SORT ARRAY DATA TO POINTS FUNCTION
//-------------------------------------------------
private PointPairList sortData(int[,] curveArray)
{
int numberOfCurves = 8;
int[,] advDegBTDC = new int[numberOfCurves,8];
int[,] rpmValues = new int[numberOfCurves,8];
int curveNumber = 0;
int arrayIndex = 0;
int genArrayIndex = 0;
// Copy data from rpmArray and advArray into rpmValues and
advDegBTDC arrays used for plots
for (curveNumber = 0; curveNumber < numberOfCurves;
curveNumber++)
{
for (arrayIndex = 0; arrayIndex < 8; arrayIndex++)
{
advDegBTDC[curveNumber,arrayIndex] =
curveArray[0,genArrayIndex];
rpmValues[curveNumber,arrayIndex] =
curveArray[1,genArrayIndex];
genArrayIndex++;
}
}
PointPairList list1 = new PointPairList();
// TEST: Just sending the first curve (8 data points) to
list1 to graph
for (int i = 0; i < 8; i++)
{
list1.Add(rpmValues[0,i], advDegBTDC[0,i]);
}
return list1;
}
}
}