Esempio n. 1
0
        // event handler for getting serial data
        private void ProcessCOMRx(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(COMRx))
            {
                string[] parsed = COMRx.Split(',');
                int      curveNo;

                if (parsed.Count() > ZedGraphControl1.GraphPane.CurveList.Count())
                {
                    curveNo = ZedGraphControl1.GraphPane.CurveList.Count();
                }
                else
                {
                    curveNo = parsed.Count();
                }


                for (int k = 0; k < curveNo; k++)
                {
                    for (int j = ZedGraphControl1.GraphPane.CurveList[k].NPts - 1; j > 0; j--)
                    {
                        ZedGraphControl1.GraphPane.CurveList[k].Points[j].Y = ZedGraphControl1.GraphPane.CurveList[k].Points[j - 1].Y;
                    }

                    double temp = 0;

                    try
                    {
                        temp = double.Parse(parsed[k]);
                    }
                    catch
                    {
                        RawTextBox.AppendText("Parse Error\n");
                    }

                    //RawTextBox.AppendText(temp.ToString() + "-" + k.ToString() + ", ");
                    ZedGraphControl1.GraphPane.CurveList[k].Points[0].X = 0;
                    ZedGraphControl1.GraphPane.CurveList[k].Points[0].Y = temp;
                }

                //RawTextBox.AppendText("\n");
                RawTextBox.AppendText(COMRx + '\n');
                //COMRx = "";
            }
        }
Esempio n. 2
0
 private void ReadLineError(object sender, EventArgs e)
 {
     RawTextBox.AppendText("Read Line Error\n");
 }
Esempio n. 3
0
        // event handler for getting serial data
        private void ProcessCOMRx(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(COMRx))
            {
                // handel incoming info from bot
                if (COMRx.Contains("#"))  // Hande non-series date here
                //Console.WriteLine("COMRx:" + COMRx);
                {
                    var vDataValue = COMRx.Substring(2, COMRx.IndexOf("#") - 2);
                    //Console.WriteLine("vDataValue:" + vDataValue);

                    if (COMRx.StartsWith("bv"))
                    {
                        BattVoltsLabel.Text = vDataValue + " Volts";
                        Console.WriteLine("got back bv");
                    }

                    if (COMRx.StartsWith("lt"))
                    {
                        lapTimeTextBox.Text = vDataValue;
                        Console.WriteLine("got back lap-time");
                    }

                    if (COMRx.StartsWith("ss"))
                    {
                        if (vDataValue == MyConstants.Stop)
                        {
                            Console.WriteLine("got back Stop");
                            bStopReceived = true;
                        }
                        else
                        {
                            Console.WriteLine("got back Start");
                            bStartReceived = true;
                        }
                    }

                    if (COMRx.StartsWith("kp"))
                    {
                        // Check off that speed was sent
                        bKpReceived = true;
                        Console.WriteLine("got back kp");
                    }

                    if (COMRx.StartsWith("ki"))
                    {
                        // Check off that speed was sent
                        bKiReceived = true;
                        Console.WriteLine("got back ki");
                    }

                    if (COMRx.StartsWith("kd"))
                    {
                        // Check off that speed was sent
                        bKdReceived = true;
                        Console.WriteLine("got back kd");
                    }

                    if (COMRx.StartsWith("sp"))
                    {
                        // Check off that speed was sent
                        bSpeedReceived = true;
                        Console.WriteLine("got back sp");
                    }
                    //return;// exit because rest of code here is for series data
                }

                if (!COMRx.Contains("#"))  // parse incoming series data
                {
                    string[] parsed = COMRx.Split(',');
                    int      curveNo;

                    if (parsed.Count() > ZedGraphControl1.GraphPane.CurveList.Count())
                    {
                        // data series count is more than stated - good
                        curveNo = ZedGraphControl1.GraphPane.CurveList.Count();
                    }
                    else
                    {
                        // data series count is not more than stated - bad
                        curveNo = parsed.Count();
                    }

                    for (int k = 0; k < curveNo; k++)
                    {
                        for (int j = ZedGraphControl1.GraphPane.CurveList[k].NPts - 1; j > 0; j--)
                        {
                            ZedGraphControl1.GraphPane.CurveList[k].Points[j].Y = ZedGraphControl1.GraphPane.CurveList[k].Points[j - 1].Y;
                        }

                        double temp = 0;

                        try {
                            temp = double.Parse(parsed[k]);
                        }
                        catch {
                            RawTextBox.AppendText("Parse Error\n");
                        }

                        ZedGraphControl1.GraphPane.CurveList[k].Points[0].X = 0;
                        ZedGraphControl1.GraphPane.CurveList[k].Points[0].Y = temp;
                    }
                    RawTextBox.AppendText(COMRx + '\n');
                    COMRx = "";
                }
            }// end if (!string.IsNullOrEmpty(COMRx))

            if (bDataSentToBot == true)  // check if all data sent to bot got sent, resent if not
            {
                if (!bSpeedReceived)
                {
                    SerialPort.WriteLine("sp" + SpeedNumericUpDown.Value + "#");
                    Console.WriteLine("resent sp");
                }

                if (!bKpReceived)
                {
                    SerialPort.WriteLine("kp" + PTermNumericUpDown.Value + "#");
                    Console.WriteLine("resent kp");
                }

                if (!bKiReceived)
                {
                    SerialPort.WriteLine("ki" + ITermNumericUpDown.Value + "#");
                    Console.WriteLine("resent ki");
                }

                if (!bKdReceived)
                {
                    SerialPort.WriteLine("kd" + DTermNumericUpDown.Value + "#");
                    Console.WriteLine("resent kd");
                }

                if (bSpeedReceived && bKiReceived && bKdReceived && bKpReceived)
                {
                    // Everything came back so reset the flag
                    bDataSentToBot = false;
                    Console.WriteLine("got back all and reset bDataSentToBot flag");
                    COMSendStatusLight.Value = MyConstants.Green;
                }
            }
        }
Esempio n. 4
0
        // event handler for getting serial data
        private void ProcessCOMRx(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(COMRx))
            {
                // handel incoming info from bot
                if (COMRx.Contains("#"))
                {
                    //Console.WriteLine("COMRx:" + COMRx);
                    var vDataValue = COMRx.Substring(2, COMRx.IndexOf("#") - 2);
                    //Console.WriteLine("vDataValue:" + vDataValue);

                    if (COMRx.StartsWith("kp"))
                    {
                        // Check off that speed was sent
                        bKpReceived = true;
                        Console.WriteLine("got back kp");
                    }

                    if (COMRx.StartsWith("ki"))
                    {
                        // Check off that speed was sent
                        bKiReceived = true;
                        Console.WriteLine("got back ki");
                    }

                    if (COMRx.StartsWith("kd"))
                    {
                        // Check off that speed was sent
                        bKdReceived = true;
                        Console.WriteLine("got back kd");
                    }

                    if (COMRx.StartsWith("sp"))
                    {
                        // Check off that speed was sent
                        bSpeedReceived = true;
                        Console.WriteLine("got back sp");
                    }
                    return;
                }

                // parse incoming data for graphing
                string[] parsed = COMRx.Split(',');
                int      curveNo;

                if (parsed.Count() > ZedGraphControl1.GraphPane.CurveList.Count())
                {
                    // data count is more than stated - good
                    curveNo = ZedGraphControl1.GraphPane.CurveList.Count();
                }
                else
                {
                    // data count is not more than stated - bad
                    curveNo = parsed.Count();
                }

                for (int k = 0; k < curveNo; k++)
                {
                    for (int j = ZedGraphControl1.GraphPane.CurveList[k].NPts - 1; j > 0; j--)
                    {
                        ZedGraphControl1.GraphPane.CurveList[k].Points[j].Y = ZedGraphControl1.GraphPane.CurveList[k].Points[j - 1].Y;
                    }

                    double temp = 0;

                    try {
                        temp = double.Parse(parsed[k]);
                    } catch {
                        RawTextBox.AppendText("Parse Error\n");
                    }

                    //RawTextBox.AppendText(temp.ToString() + "-" + k.ToString() + ", ");
                    ZedGraphControl1.GraphPane.CurveList[k].Points[0].X = 0;
                    ZedGraphControl1.GraphPane.CurveList[k].Points[0].Y = temp;
                }
                //RawTextBox.AppendText("\n");
                RawTextBox.AppendText(COMRx + '\n');
                COMRx = "";
            }

            if (bDataSentToBot == true)
            {
                if (!bSpeedReceived)
                {
                    SerialPort.WriteLine("sp" + SpeedNumericUpDown.Value + "#");
                    Console.WriteLine("resent sp");
                }

                if (!bKpReceived)
                {
                    SerialPort.WriteLine("kp" + PTermNumericUpDown.Value + "#");
                    Console.WriteLine("resent kp");
                }

                if (!bKiReceived)
                {
                    SerialPort.WriteLine("ki" + ITermNumericUpDown.Value + "#");
                    Console.WriteLine("resent ki");
                }

                if (!bKdReceived)
                {
                    SerialPort.WriteLine("kd" + DTermNumericUpDown.Value + "#");
                    Console.WriteLine("resent kd");
                }

                if (bSpeedReceived && bKiReceived && bKdReceived && bKpReceived)
                {
                    // Everything came back so reset the flags
                    bDataSentToBot = false;
                    Console.WriteLine("got back all and reset bDataSentToBot flag");
                    COMPortSendStatusLight.Value = 0;
                }
            }
        }