Exemplo n.º 1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            GraphPane     myPane        = zedGraphControl1.GraphPane;
            PointPairList listPointsTwo = new PointPairList();
            string        selected      = comboBox1.Text;

            ACOK.SipRegisters sel = EnumDescriptor.ToEnum <ACOK.SipRegisters>(selected);
            if (selected == "Data1")
            {
                Dispdata(sel);
                //button6_Click(this, null);
            }
            if (selected != "Data1")
            {
                //if (axisflag == 1)
                //{
                //    myPane.YAxis.Max = 40;
                //    myPane.YAxis.Min = 0;
                //    myPane.XAxis.Min = 0;
                //    myPane.XAxis.Max = 50;
                //}

                if (i * yscalectrl > myPane.XAxis.Max - 5)
                {
                    myPane.XAxis.Max = (i + 10);
                    axisflag         = 0;
                }
                i++;


                Sipval[(i - 1)] = Data.GetVal(sel);


                zedGraphControl1.AxisChange();
                zedGraphControl1.Refresh();

                myPane.ScaledGap(1);

                Rangscale(sel);


                myPane.IsFontsScaled = true;


                PointPairList approx2 = new PointPairList();


                if (i > 1)
                {
                    a = (sumxy * (i - 1) - sumy * sumx) / (sumx2 * (i - 1) - Math.Pow(sumx, 2));
                    b = (sumy - a * sumx) / (i - 1);
                    for (double x = i - 1; x <= i; x += 0.5)
                    {
                        approx2.Add(x, a1 * x + b1);
                    }
                }
                sumx  += i;
                sumy  += Data.GetVal(sel);
                sumx2 += Math.Pow(i, 2);
                sumxy += i * Data.GetVal(sel);

                a = (sumxy * i - sumy * sumx) / (sumx2 * i - Math.Pow(sumx, 2));
                b = (sumy - a * sumx) / i;
                PointPairList approx1 = new PointPairList();
                approx1.Clear();
                for (double x = 1; x <= i; x += 0.5)
                {
                    approx1.Add(x, a * x + b);
                }

                /*
                 * LineItem f1_curve = myPane.AddCurve(null, approx1, Color.Black, SymbolType.None);
                 */
                myPane.CurveList.Clear();

                for (int u = 0; u < Sipval.Length; u++)
                {
                    listPointsTwo.Add(u + 1, Sipval[u]);
                }
                LineItem myCurveTwo = myPane.AddCurve("real T", listPointsTwo, Color.Black, SymbolType.None);
                if (i > 2)
                {
                    bezcurv(Sipval, i);
                }
                Array.Resize <double>(ref Sipval, Sipval.Length + 1);

                //byte[] temBuf = new byte[4];
                //int index = 0;

                //private void COM3_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
                //{

                //    ////byte[] tempval = new byte[3];
                //    //int[] tempval = new int[3];// tempval[3];
                //    //int j = 0;

                //        int count = COM3.BytesToRead;
                //        while (count > 0)
                //        {
                //            byte[] buf = new byte[count];
                //            COM3.Read(buf, 0, count);

                //            int wrCount = ((temBuf.Length - index) < count) ? count : count; //(temBuf.Length - index);
                //            Array.Copy(buf, 0, temBuf, index, wrCount);

                //            index += wrCount;
                //            if (index >= temBuf.Length)
                //            {
                //                index = 0;
                //                float temp = 0;
                //                try
                //                {
                //                    temp = BitConverter.ToSingle(temBuf, 0);
                //                }
                //                catch {}

                //                richTextBox1.Invoke(new Action(() =>
                //                {
                //                    richTextBox2.Text = string.Format("{0:F3}", temp); ;
                //                }));
                //            }

                //            //tempval[j]= COM3.Read(buf, 0, count);
                //            //richTextBox4.Text += tempval[j];
                //            //j++;
                //            //if (j > 2)
                //            //{
                //            //    j = 0;
                //            //};



                //            //string strB = "";
                //            //for (int i = 0; i < count; i++)
                //            //{
                //            //    strB += string.Format("{0:X2}", buf[i]);
                //            //    strB += "\t";
                //            //}

                //            //richTextBox1.Invoke(new Action(() =>
                //            //{
                //            //   richTextBox2.Text += strB;
                //            //}));

                //            count = COM3.BytesToRead;
                //        }
                //    }

                //private void COM3_ErrorReceived(object sender, System.IO.Ports.SerialErrorReceivedEventArgs e)
                //{

                //}
                //
                #endregion // Events
                //-------------------------------------------------------------------------



                //button1_Click_1(this, null);
            }
        }