How to pass more than 2 parameters in C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dondigitech LaPel

    #1

    How to pass more than 2 parameters in C#

    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 initializeIgnCo mm 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.Collecti ons.Generic;
    using System.Componen tModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.IO.Ports ;
    using System.Windows. Forms;
    using System.Threadin g;
    using PCComm;
    using PortSet;
    using ZedGraph;

    namespace PCComm
    {
    public partial class frmMain : Form
    {
    CurveData comm = new CurveData();
    string transType = string.Empty;

    public frmMain()
    {
    InitializeCompo nent();
    }

    private void frmMain_Load(ob ject sender, EventArgs e)
    {
    //SetDefaults();
    }

    # region MENU STRIP CONTROL

    //<<<<<<<<< SERIAL PORT SETTINGS MENU >>>>>>>>>>//
    private void settingsToolStr ipMenuItem_Clic k1(object sender,
    EventArgs e)
    {
    // Make sure the port isn't already open
    if (serialPort1.Is Open)
    {
    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.ShowD ialog() == DialogResult.OK )
    {
    if (settings.selec tedPort != "")
    {
    // Set the serial port to the new settings
    serialPort1.Por tName = settings.select edPort;
    serialPort1.Bau dRate =
    settings.select edBaudrate;
    showSettings();
    }
    else
    {
    MessageBox.Show ("Error: Settings form returned
    with no COM port selected.");
    return; // bail out
    }
    }
    else
    {
    MessageBox.Show ("Error: buttonSetup_Cli ck - Settings
    dialog box did not return Okay.");
    return; // bail out
    }
    // Open the port
    try
    {
    serialPort1.Clo se();
    serialPort1.Ope n();
    menuStrip1.Item s[1].Text = "Close Port";
    showSettings();
    }
    catch (System.Excepti on ex)
    {
    MessageBox.Show ("Error -
    setupToolStripM enuItem_Click Exception: " + ex);
    }
    }
    }

    //<<<<<<<<< OPEN/CLOSE PORT BUTTON >>>>>>>>>>//
    private void openPortToolStr ipMenuItem_Clic k(object sender,
    EventArgs e)
    {
    try
    {
    if (serialPort1.Is Open)
    {
    serialPort1.Clo se();
    menuStrip1.Item s[1].Text = "Open Port";
    }
    else
    {
    serialPort1.Ope n();
    menuStrip1.Item s[1].Text = "Close Port";
    }

    showSettings();
    }
    catch (System.Excepti on ex)
    {
    MessageBox.Show ("Error - openPortToolStr ipMenuItem_Clic k
    Exception: " + ex);
    }
    }

    private void GroupBox1_Enter (object sender, EventArgs e)
    {

    }

    //<<<<<<<<< GET CURVES BUTTON >>>>>>>>>>//
    private void getCurvesToolSt ripMenuItem_Cli ck(object sender,
    EventArgs e, int[,] curveArray)
    {
    comm.DisplayWin dow = rtbDisplay;
    try
    {
    if (serialPort1.Is Open)
    {
    comm.initialize IgnComm(serialP ort1);
    plotCurves(zedG raphControl1, curveArray);
    }
    else
    {
    MessageBox.Show ("Error: COM port closed.");
    return; // bail out
    }
    }
    catch (System.Excepti on ex)
    {
    MessageBox.Show ("Error - findIgnButton_C lick Exception:
    " + ex);
    }

    }
    #endregion

    # region CURVE ID HEADER
    private void showSettings()
    {
    this.Text = "DYNATEK IGNITIONS - " +
    serialPort1.Por tName + " " +
    serialPort1.Bau dRate.ToString( );
    if (serialPort1.Is Open)
    {
    this.Text += " - Port is open";
    }
    else
    {
    this.Text += " - Port is closed";
    }
    }
    #endregion

    # region GRAPH CURVES
    private void zedGraphControl 1_Load(object sender, EventArgs e)
    {
    }

    private void plotCurves(ZedG raphControl 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(curveA rray); //Sort data into
    list for plotting

    LineItem ignCurve = plotCurve.AddCu rve("WOT Curve 4",
    curve1, Color.Red, SymbolType.Diam ond);
    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,arr ayIndex] =
    curveArray[0,genArrayIndex];
    rpmValues[curveNumber,arr ayIndex] =
    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(rpmVa lues[0,i], advDegBTDC[0,i]);
    }
    return list1;

    }
    }
    }

    *** Sent via Developersdex http://www.developersdex.com ***
  • Peter Duniho

    #2
    Re: How to pass more than 2 parameters in C#

    On Fri, 31 Oct 2008 09:47:28 -0700, dondigitech LaPel
    <dlapel@dynaonl ine.comwrote:
    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. [...]
    Is this related to the previous thread you started? Is this code in any
    way different from the previous code you posted? Is there some particular
    reason you are starting a new thread rather than following up in the
    previous thread, where I already replied to a post that looks remarkably
    similar to the one you just made?

    Comment

    • Jeff Johnson

      #3
      Re: How to pass more than 2 parameters in C#

      "dondigitec h LaPel" <dlapel@dynaonl ine.comwrote in message
      news:e8GLdh3OJH A.1960@TK2MSFTN GP04.phx.gbl...
      Ultimately the issue I am having is getting/passing the curveArray data
      to the event handler.
      I'm going to reply in the original thread. Do NOT start multiple threads for
      the same question. The regulars that are most likely to help you are also
      very likely to be put off by this bad Netiquette.


      Comment

      Working...