Ejemplo n.º 1
0
        internal void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            if (curve == null)
            {
                buttons.Add(GraphProcessing.CreateCurve(ref curve, curvesDropDownBtn, planeGraph, "Основной График", Color.Red, 2, SymbolType.Circle, Color.Red));
                ZGCInstance.GraphPane.YAxis.Title.Text = "F, условных единиц";
                ZGCInstance.GraphPane.XAxis.Title.Text = "N, оборотов";
                curve.Tag = 3;
            }
            // Логика за этим? Зачем таймер.
            drawGraphMethod print = new drawGraphMethod(GraphProcessing.AddInRealTime); //Инициализация переменных для ком-порта
            // Show all the incoming data in the port's buffer
            string comPortData = ((SerialPort)sender).ReadExisting().ToString();        //Чтение данных из текущего ком порта.

            comPortData = comPortData.Replace("0\r#0", " ");                            //Удаление символов перехода строки
            comPortData = comPortData.Replace("\t", " ");
            int lengthOfOneReading = Parsing.GetLengthOfOneReading(comPortData);

            counterTimer  = 0;
            saveTimerTick = 0;
            while (lengthOfOneReading > 0 && comPortData.Length > lengthOfOneReading) //Перебираем все пары усилий и поворотов в полученной строке
            {
                if (everySecond == null)
                {
                    СreateTimer();
                }

                atLeastOnePointPassed = true;
                lengthOfOneReading    = Parsing.GetLengthOfOneReading(comPortData);
                string tempStr = comPortData.Substring(0, lengthOfOneReading); //Если в полученной строке несколько показаний, отделяем одно
                comPortData = comPortData.Substring(lengthOfOneReading);       // Вся остальная строка
                TwoCordLinkedList.Node temp = Parsing.ProcessDataMK2(tempStr, coefficient);
                listOfPoints.addLast(temp);
                if (!firstValue && temp != null)
                {
                    xMin = temp.X; firstValue = true;
                }

                if (temp != null) // Отрисовка добавленной в список точки
                {
                    try
                    {
                        planeGraph.Invoke((Action)(() => print(curve, (double)temp.X - xMin, temp.Y)));
                        planeGraph.Invoke((Action)(() => GraphProcessing.UpdateGraph(planeGraph)));
                        planeGraph.Invoke((Action)(() => GraphProcessing.calculateSize(ZGCInstance)));
                    }
                    catch (Exception ex) { }
                }
            }
        }
Ejemplo n.º 2
0
        public void DrawLinearPart()
        {
            if (curve != null)
            {
                if (lineCurve != null)
                {
                    planeGraph.GraphPane.CurveList.Remove(lineCurve);
                    curvesDropDownBtn.DropDownItems.Remove(linearPart.button);
                    buttons.Remove(linearPart);
                    linearPart = null;
                    lineCurve  = null;
                }
                linearPart = GraphProcessing.CreateCurve(ref lineCurve, curvesDropDownBtn, planeGraph, "Линейный участок", Color.Blue, 8, SymbolType.Circle, Color.Blue);
                buttons.Add(linearPart);
                lineCurve.Label.IsVisible = false;
                LineItem firstDerivativeCurve = new LineItem("d1");
                firstDerivativeCurve.Tag = 5;
                LineItem firstMovingAverageCurve = new LineItem("mad1");
                firstMovingAverageCurve.Tag = 5;
                processedCurve = new LineItem("movingAverage1");

                processedCurve.Tag  = 5;
                processedCurve2     = new LineItem("movingAverage2");
                processedCurve2.Tag = 5;
                double[] data = GraphProcessing.CurveToArray(curve, false);

                double[] movingAverage1 = GraphProcessing.MovingAverage(data, sensitivy);
                for (int i = 0; i < movingAverage1.Length - 1; i++)
                {
                    processedCurve2.AddPoint(curve.Points[i].X, movingAverage1[i]);
                }
                linearPart.curve.IsVisible = false;
                processedCurve             = processedCurve2.Clone();

                GraphProcessing.DerivativeGraph(curve, ref firstDerivativeCurve);

                GraphProcessing.SecondDerivativeGraph(firstDerivativeCurve, ref secondDerivativeCurve);
                GraphProcessing.DerivativeGraph(processedCurve, ref firstMovingAverageCurve);
                LineItem tempCurve = new LineItem("temp");
                tempCurve.Tag = 5;
                LineItem secondMovingAverageCurve = new LineItem("sMAC");
                secondMovingAverageCurve.Tag = 5;
                GraphProcessing.DerivativeGraph(processedCurve2, ref tempCurve);
                GraphProcessing.DerivativeGraph(tempCurve, ref secondMovingAverageCurve);
                int[] bounds = GraphProcessing.CalculatePointsForLinear(curve, secondMovingAverageCurve, firstMovingAverageCurve);
                for (int i = bounds[0]; i < bounds[1]; i++)
                {
                    lineCurve.AddPoint(curve[i]);
                }

                aproximateLinearCurve = null;
                int begin = (int)bounds[0];
                int end   = (int)bounds[1];
                buttons.Add(GraphProcessing.CreateCurve(ref aproximateLinearCurve, curvesDropDownBtn, planeGraph, "Линейный участок МНК", Color.Green, 2, SymbolType.Circle, Color.Green));
                //(int) curve.Points[begin].X (int) curve.Points[end].X
                // y= y1+(x-x1) (y2 - y1) / (x2-x1) ; y = k*(x-x1) + y1 = kx - (kx1 + y1)
                MyMath.leastSquaresBuild((int)curve.Points[begin].X, (int)curve.Points[end].X, lineCurve, ref aproximateLinearCurve, this);
                aproximateLinearCurve.Tag             = 2;
                form.AproximateLinearCurve            = aproximateLinearCurve;
                aproximateLinearCurve.IsVisible       = false;
                aproximateLinearCurve.Label.IsVisible = false;
                lineCurve.Tag = 5;
                planeGraph.Refresh();
                GraphProcessing.UpdateGraph(planeGraph);
            }
            else
            {
                ErrorMessage form = new ErrorMessage("Нет графика на котором нужно найти линейный участок");
            }



            Task.Delay(1500);
            var customLineForm = new CustomLine(this);

            customLineForm.Show();
            customLineForm.Activate();
            customLineForm.Focus();
            customLineForm.BringToFront();
        }