private void DrawGraph(ZedGraphControl DoThi, List <PredicResults> results)
        {
            //ve gia tri
            LineItem curve2_1 = DoThi.GraphPane.CurveList[0] as LineItem;
            LineItem curve2_2 = DoThi.GraphPane.CurveList[1] as LineItem;

            //init do thi.

            // Get the PointPairList
            IPointListEdit list21 = curve2_1.Points as IPointListEdit;
            IPointListEdit list22 = curve2_2.Points as IPointListEdit;

            list21.Clear();
            list22.Clear();
            DoThi.AxisChange();
            DoThi.Invalidate();
            int i = 0;

            foreach (var item in results)
            {
                var xdate = new XDate(item.Date);
                list21.Add(xdate, item.ActualClose);
                list22.Add(xdate, item.PredictedClose);
                // đoạn chương trình thực hiện vẽ đồ thị
                Scale xScale = DoThi.GraphPane.XAxis.Scale;
                i++;
            }
            // Vẽ đồ thị
            DoThi.AxisChange();
            // Force a redraw
            DoThi.Invalidate();
        }
Example #2
0
        public void DrawGraph(List <MyError> results)
        {
            //ve gia tri
            LineItem curve2_1 = DoThi_Error.GraphPane.CurveList[0] as LineItem;
            // LineItem curve2_2 = DoThi.GraphPane.CurveList[1] as LineItem;

            //init do thi.

            // Get the PointPairList
            IPointListEdit list21 = curve2_1.Points as IPointListEdit;

            list21.Clear();

            DoThi_Error.AxisChange();
            DoThi_Error.Invalidate();
            int i = 0;

            foreach (var item in results)
            {
                list21.Add(item.index, item.value);

                // đoạn chương trình thực hiện vẽ đồ thị
                Scale xScale = DoThi_Error.GraphPane.XAxis.Scale;
                i++;
            }

            // Vẽ đồ thị
            DoThi_Error.AxisChange();
            // Force a redraw
            DoThi_Error.Invalidate();

            //if (AppGlobol.IsAutoRun)
            //    DoThi_Error.GetImage().Save(AppGlobol.FolderPath + "/Error.png");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.Title    = "Open File...";
            openFileDialog1.FileName = "";
            openFileDialog1.Filter   = "CSV (comma delimited)|*.csv|All Files|*.*";

            if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
            {
                MessageBox.Show("Choice Cancelled");
            }
            else
            {
                data          = File.ReadAllLines(openFileDialog1.FileName);
                dataMagnitude = data.Select(x => double.Parse(x)).ToArray();

                N     = Enumerable.Range(1, dataMagnitude.Length).ToArray();
                dataN = Array.ConvertAll <int, double>(N, Convert.ToDouble);

                LineItem       kurvaMagnitude = zedGraphControl1.GraphPane.CurveList[0] as LineItem;
                IPointListEdit listMagnitude  = kurvaMagnitude.Points as IPointListEdit;
                listMagnitude.Clear();
                for (int i = 1; i < dataMagnitude.Length; i++)
                {
                    listMagnitude.Add(dataN[i], dataMagnitude[i]);
                }
                zedGraphControl1.AxisChange();
                zedGraphControl1.Invalidate();
            }
        }
Example #4
0
 public void Clear()
 {
     ptsSavepoints.Clear();
     ptsTraining.Clear();
     ptsValidation.Clear();
     ptsCurrentSavepoint.Clear();
 }
Example #5
0
        /// <summary>
        /// Updates the ZedGraph
        /// </summary>
        /// <param name="zedGraph"></param>
        /// <param name="Data"></param>
        /// <param name="time"></param>
        public void UpdateZedGraph(ZedGraphControl zedGraph, Int16[] Data, int time)
        {
            if (zedGraph.GraphPane == null)
            {
                return;
            }

            int    localTime = 0;
            double seconds   = 0;

            rect = new Rectangle((int)zedGraph.GraphPane.Chart.Rect.X, (int)zedGraph.GraphPane.Chart.Rect.Y, (int)zedGraph.GraphPane.Chart.Rect.Width, (int)zedGraph.GraphPane.Chart.Rect.Height);

            // Make sure that the curvelist has at least one curve
            if (zedGraph.GraphPane.CurveList.Count <= 0)
            {
                return;
            }

            // Get the first CurveItem in the graph
            LineItem curve = zedGraph.GraphPane.CurveList[0] as LineItem;

            if (curve == null)
            {
                return;
            }

            // Get the PointPairList
            IPointListEdit list = curve.Points as IPointListEdit;

            //If time hits zero, Graph gets cleared and redrawn
            if (time == 0)
            {
                list.Clear();
                // Force a redraw
                //zedGraph.Invalidate();
            }

            // If this is null, it means the reference at curve.Points does not
            // support IPointListEdit, so we won't be able to modify it
            if (list == null)
            {
                return;
            }

            for (int i = 0; i < Data.Length; i++)
            {
                seconds = (double)(time + localTime) / Statics.FS;
                // Time is measured in seconds
                localTime++;
                // 3 seconds per cycle
                list.Add(seconds, Data[i]);
            }

            //Only redraw a certain area
            var xPix = (int)zedGraph.GraphPane.XAxis.Scale.Transform(seconds);

            rect.X     = xPix - ((int)zedGraph.GraphPane.Chart.Rect.Width / 6); //- 20;
            rect.Width = (int)zedGraph.GraphPane.Chart.Rect.Width / 6 + 10;
            zedGraph.Invalidate(rect);
        }
        // ------------------  CHARTING ROUTINES ---------------------

        /// <summary> Sets up the chart. </summary>
        public void SetupChart()
        {
            MasterPane masterPane = chartControl.MasterPane;
            masterPane.PaneList.Clear();

            // get a reference to the GraphPane

            _temperaturePane = new GraphPane(new Rectangle(5, 5, 890, 350),
                "Temperature controller",
                "Time (s)",
                "Temperature (C)");
            masterPane.Add(_temperaturePane);

            // Create data arrays for rolling points
            _analog1List = new RollingPointPairList(3000);
            _analog3List = new RollingPointPairList(3000);
            _analog1List.Clear();
            _analog3List.Clear();

            // Create a smoothened red curve for the current temperature
            LineItem myCurve1 = _temperaturePane.AddCurve("Current temperature", _analog1List, Color.Red, SymbolType.None);
            myCurve1.Line.Width = 2;
            myCurve1.Line.IsSmooth = true;
            myCurve1.Line.SmoothTension = 0.2f;


            // Create a smoothened blue curve for the goal temperature
            LineItem myCurve3 = _temperaturePane.AddCurve("Goal temperature", _analog3List, Color.Blue, SymbolType.None);
            myCurve3.Line.Width = 2;
            myCurve3.Line.IsSmooth = true;
            myCurve3.Line.SmoothTension = 0.2f;
            // Tell ZedGraph to re-calculate the axes since the data have changed
            chartControl.AxisChange();

            _heaterPane = new GraphPane(new Rectangle(5, 360, 890, 250),
                null,
                null,
                null);
            masterPane.Add(_heaterPane);
            
            _heaterList = new RollingPointPairList(3000);
            _heaterPwmList = new RollingPointPairList(3000);
            _heaterList.Clear();
            _heaterPwmList.Clear();

            // Create a red curve for the heater value
            LineItem heaterCurve = _heaterPane.AddCurve(null, _heaterList, Color.YellowGreen, SymbolType.None);
            heaterCurve.Line.Width = 2;
            heaterCurve.Line.IsSmooth = false;

            // Create a red curve for the current heater pwm value
            LineItem heaterPwmCurve = _heaterPane.AddCurve(null, _heaterPwmList, Color.Blue, SymbolType.None);
            heaterPwmCurve.Line.Width = 2;
            heaterPwmCurve.Line.IsSmooth = false;

            SetChartScale(0);
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            LineItem       kurvaMagnitude = zedGraphControl1.GraphPane.CurveList[0] as LineItem;
            IPointListEdit listMagnitude  = kurvaMagnitude.Points as IPointListEdit;

            dataMagnitude = new double[1000];

            try
            {
                for (int i = 0; i < 1000; i++)
                {
                    dataMagnitude[i] = double.Parse(uno.ReadLine(), CultureInfo.InvariantCulture.NumberFormat);
                }
            }
            catch (Exception)
            {
                //uno.Close();
                return;
            }


            OnlineFilter bandpass = OnlineFilter.CreateBandpass(MathNet.Filtering.ImpulseResponse.Finite, 1000, 20, 500);
            OnlineFilter bandstop = OnlineFilter.CreateBandstop(MathNet.Filtering.ImpulseResponse.Finite, 1000, 48.5, 51.5);
            OnlineFilter denoise  = OnlineFilter.CreateDenoise();

            dataFilter = new double[1000];
            dataFilter = bandpass.ProcessSamples(dataMagnitude);
            dataFilter = bandstop.ProcessSamples(dataFilter);
            dataFilter = denoise.ProcessSamples(dataFilter);
            var N = Enumerable.Range(1, dataMagnitude.Length).ToArray();

            waktu = Array.ConvertAll <int, double>(N, Convert.ToDouble);



            // double waktu = (Environment.TickCount - waktustart) / 1000.0;
            listMagnitude.Clear();

            for (int i = 0; i < 1000; i++)
            {
                listMagnitude.Add(waktu[i], dataFilter[i]);
            }

            label1.Text = Convert.ToString(dataFilter[500]);
            //uno.Close();



            zedGraphControl1.AxisChange();
            zedGraphControl1.Refresh();
        }
Example #8
0
        private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            if (serialPort1.IsOpen == true && run == 1)
            {
                mydata = new byte[200];
                for (int i = 0; i < 4; i++)
                {
                    mydata[i] = (byte)serialPort1.ReadByte();
                }
                while (!(mydata[0] == 0 && mydata[1] == 255 && mydata[2] == 0 && mydata[3] == 255))
                {
                    mydata[0] = mydata[1];
                    mydata[1] = mydata[2];
                    mydata[2] = mydata[3];
                    mydata[3] = (byte)serialPort1.ReadByte();
                }
                for (int i = 0; i < samples; i++)
                {
                    mydata[i] = (byte)serialPort1.ReadByte();
                }
                //serialPort1.Read(mydata, 0, samples);
                //MessageBox.Show("Reading Done");

                IPointListEdit ip = zg1.GraphPane.CurveList["Channel1"].Points as IPointListEdit;
                if (ip != null)
                {
                    //MessageBox.Show("Reading Done");
                    ip.Clear();
                    double x;
                    double y;
                    for (int i = 0; i < samples; i++)
                    {
                        x = (((10.0 * (double)i) / (double)samples) - 5.0);;
                        y = (((10.0 * (double)mydata[i]) / 255.0) - 5.0);
                        ip.Add(x, y);
                    }
                    zg1.AxisChange();
                    zg1.Invalidate();
                }
                serialPort1.DiscardInBuffer();
                byte[] writedata = { 190 };
                serialPort1.Write(writedata, 0, 1);
            }
        }
Example #9
0
        public void Clear()
        {
            if (zedgraphControl.GraphPane.CurveList.Count <= 0)
            {
                return;
            }
            LineItem curve = zedgraphControl.GraphPane.CurveList[0] as LineItem;

            if (curve == null)
            {
                return;
            }
            IPointListEdit list = curve.Points as IPointListEdit;

            if (list == null)
            {
                return;
            }
            list.Clear();
        }
Example #10
0
        /// <summary>
        ///   1. Handles all response data sent from Arduino.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void processIncomingPortData(object sender, SerialDataReceivedEventArgs e)
        {
            SerialPort arduinoPort = (SerialPort)sender;

            for (int i = 0; i < arduinoPort.BytesToRead; i++)
            {
                double volts = (double)Convert.ToInt32(arduinoPort.ReadByte()) / 51.0;
                a0PointsList.Add(yPointer, volts);
                if (yPointer == 300)
                {
                    a0PointsList.Clear();
                }
                yPointer = yPointer < 300 ? yPointer + 1 : 0;

                //Track rolling average volts for last learnSampleSize samples
                updateStats(volts);
            }

            updateGraph();
            Thread.Sleep(5);
        }
Example #11
0
        public void clearLine(int iIndex)
        {
            if (zed1.GraphPane.CurveList.Count <= 0)
            {
                return;
            }

            LineItem curve = zed1.GraphPane.CurveList[iIndex] as LineItem;

            if (curve == null)
            {
                return;
            }

            IPointListEdit list = curve.Points as IPointListEdit;

            if (list != null)
            {
                list.Clear();
            }

            zed1.Invalidate();
        }
Example #12
0
        private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            IPointListEdit ip = zg1.GraphPane.CurveList["Channel1"].Points as IPointListEdit;

            if (ip != null)
            {
                ip.Clear();
                double x;
                double y;
                if (hScrollBar1.Value > 0)
                {
                    for (int i = (hScrollBar1.Value * samples) / 100; i < samples; i++)
                    {
                        if (i - (hScrollBar1.Value * samples) / 100 >= 0)
                        {
                            x = (((10.0 * (double)i) / (double)samples) - 5.0);;
                            y = (((10.0 * (double)mydata[i - (hScrollBar1.Value * samples) / 100]) / 255.0) - 5.0);
                            ip.Add(x, y);
                        }
                    }
                }
                else if (hScrollBar1.Value < 0)
                {
                    for (int i = 0; i < samples + (hScrollBar1.Value * samples) / 100; i++)
                    {
                        if (i - (hScrollBar1.Value * samples) / 100 >= 0)
                        {
                            x = (((10.0 * (double)i) / (double)samples) - 5.0);;
                            y = (((10.0 * (double)mydata[i - (hScrollBar1.Value * samples) / 100]) / 255.0) - 5.0);
                            ip.Add(x, y);
                        }
                    }
                }
                zg1.AxisChange();
                zg1.Invalidate();
            }
        }
Example #13
0
        private void button2_Click(object sender, EventArgs e)
        {
            dataFilter = new double[dataMagnitude.Length];
            OnlineFilter bandpass = OnlineFilter.CreateBandpass(ImpulseResponse.Finite, 1000, 20, 500);
            OnlineFilter bandstop = OnlineFilter.CreateBandstop(MathNet.Filtering.ImpulseResponse.Finite, 1000, 49, 51);
            OnlineFilter denoise  = OnlineFilter.CreateDenoise();

            dataFilter = bandpass.ProcessSamples(dataMagnitude);
            dataFilter = bandstop.ProcessSamples(dataFilter);
            dataFilter = denoise.ProcessSamples(dataFilter);

            LineItem       kurvaMagnitude = zedGraphControl1.GraphPane.CurveList[1] as LineItem;
            IPointListEdit listFilter     = kurvaMagnitude.Points as IPointListEdit;

            listFilter.Clear();
            for (int i = 1; i < dataFilter.Length; i++)
            {
                listFilter.Add(dataN[i], dataFilter[i]);
            }
            zedGraphControl1.AxisChange();
            zedGraphControl1.Invalidate();
            button2.Enabled = false;
            button3.Enabled = true;
        }
Example #14
0
        /**
         * Redraw graph, See ZedGraph documents for more details
         */
        private void Redraw(int dPtr)
        {
            int i, dMin;

            if (zgc.GraphPane.CurveList.Count <= 0)
            {
                return;
            }
            // Get the first CurveItem in the graph
            LineItem curve1 = zgc.GraphPane.CurveList["Humidity"] as LineItem;
            LineItem curve2 = zgc.GraphPane.CurveList["Temperature"] as LineItem;
            LineItem curve3 = zgc.GraphPane.CurveList["Pressure"] as LineItem;

            if (curve3 == null)
            {
                return;
            }
            // Get the PointPairList
            IPointListEdit list1 = curve1.Points as IPointListEdit;
            IPointListEdit list2 = curve2.Points as IPointListEdit;
            IPointListEdit list3 = curve3.Points as IPointListEdit;

            list1.Clear();
            list2.Clear();
            list3.Clear();
            // If this is null, it means the reference at curve.Points does not
            // support IPointListEdit, so we won't be able to modify it
            for (i = 0; i < w.Length; i++)
            {
                if (++dPtr >= w.Length)
                {
                    dPtr = 0;
                }
                if (w[dPtr].time != new XDate(1970, 1, 1))
                {
                    break;
                }
            }
            dMin = dPtr;
            zgc.GraphPane.XAxis.Title.Text = "Date " + w[dMin].time.ToString("dd/MM/yyyy");
            for (i = 0; i < w.Length; i++)
            {
                if (w[dPtr].time != new XDate(1970, 1, 1))
                {
                    list1.Add(w[dPtr].time, w[dPtr].humidity);
                    list2.Add(w[dPtr].time, w[dPtr].temp);
                    list3.Add(w[dPtr].time, w[dPtr].pressure);
                    wIndex = dPtr;
                }
                else
                {
                    break;
                }
                if (++dPtr >= w.Length)
                {
                    dPtr = 0;
                }
            }
            if (w[wIndex].time.DateTime.DayOfYear != w[dMin].time.DateTime.DayOfYear)
            {
                zgc.GraphPane.XAxis.Title.Text += " - " + w[wIndex].time.ToString("dd/MM/yy");
            }
            //zgc.GraphPane.XAxis.Scale.MajorStep = s.interval * 10;
            // Make sure the Y axis is rescaled to accommodate actual data
            zgc.AxisChange();
            // Force a redraw
            zgc.Invalidate();
        }
Example #15
0
        // this section executes every time there is a timer1 tick (1ms in this case)
        private void timer1_Tick_1(object sender, EventArgs e)
        {
            // increases the counter
            counter++;

            #region GraphEvents
            // Make sure that the curvelist has at least one curve
            if (zg1.GraphPane.CurveList.Count <= 0)
            {
                return;
            }

            // Get the first CurveItem in the graph
            LineItem curve = zg1.GraphPane.CurveList[0] as LineItem;
            if (curve == null)
            {
                return;
            }

            // Get the PointPairList
            IPointListEdit list = curve.Points as IPointListEdit;
            // If this is null, it means the reference at curve.Points does not
            // support IPointListEdit, so we won't be able to modify it
            if (list == null)
            {
                return;
            }
            Scale xScale = zg1.GraphPane.XAxis.Scale;

            // restarts the list and x axis
            if (counter < 2)
            {
                xScale.MinAuto = true;
                list.Clear();
            }

            #endregion

            #region Graph Data Points

            // Time is measured in seconds
            time = (Environment.TickCount - TimeStart) / 1000.0;

            // this section converts the data received into pressure and handles catches any exeption if the
            // data received isn't in a readable format
            if (RcvData == null)
            {
                PressurekPa = 0;
            }
            else
            {
                try
                {
                    PressurekPa = (Convert.ToSingle(RcvData) - 105) / 1024 * 5 / 0.267f / 0.14503773773021f;
                }
                catch { }
            }

            // shows in a text box the Pressure
            textBox1.Text = Convert.ToString(PressurekPa);
            textBox1.Show();

            // on each tick a new set of points is added to list (which holds the data points)
            list.Add(time, PressurekPa);

            #endregion

            #region GraphEvents2

            // Keep the X scale at a rolling 30 second interval, with one
            // major step between the max X value and the end of the axis
            if (time > xScale.Max - xScale.MajorStep)
            {
                xScale.Max = time + xScale.MajorStep;
                xScale.Min = xScale.Max - 30.0;
            }

            //Make sure the Y axis is rescaled to accommodate actual data
            zg1.AxisChange();
            //Force a redraw
            zg1.Invalidate();
            #endregion
        }
Example #16
0
        //update results based on changed data
        public void UpdateResults(List <double[]> data)
        {
            lstXYPlotdata = data;

            if ((lstXYPlotdata == null) || (lstXYPlotdata.Count < 1))
            {
                zedGraphControl1.GraphPane.CurveList[0].Clear();
                zedGraphControl1.Refresh();
                return;
            }

            // Make sure that the curvelist has at least one curve
            if (zedGraphControl1.GraphPane.CurveList.Count <= 0)
            {
                return;
            }

            // Get the first CurveItem in the graph
            LineItem curve = zedGraphControl1.GraphPane.CurveList[0] as LineItem;

            if (curve == null)
            {
                return;
            }

            // Get the PointPairList
            IPointListEdit list = curve.Points as IPointListEdit;

            // If this is null, it means the reference at curve.Points does not
            // support IPointListEdit, so we won't be able to modify it
            if (list == null)
            {
                return;
            }

            list.Clear();

            double maxX = Double.NegativeInfinity;
            double maxY = Double.NegativeInfinity;
            double minX = 0;
            double minY = 0;

            for (int i = 0; i < data.Count; i++)
            {
                list.Add(data[i][0], data[i][1]);
                if (data[i][0] > maxX)
                {
                    maxX = data[i][0];
                }
                if (data[i][1] > maxY)
                {
                    maxY = data[i][1];
                }
                if (data[i][0] < minX)
                {
                    minX = data[i][0];
                }
                if (data[i][1] < minY)
                {
                    minY = data[i][1];
                }
            }

            //if data out of range of thresholds, make the threshold plot lines bigger
            if (dblDecisionThreshold > maxX)
            {
                maxX = dblMandateThreshold;                              //_decisionThreshold;
            }
            if (dblMandateThreshold > maxY)
            {
                maxY = dblDecisionThreshold;                             //_mandateThreshold;
            }
            //find the model error counts for the XYplot display
            ModelErrorCounts mec = new ModelErrorCounts();

            mec.getCounts(dblDecisionThreshold, dblMandateThreshold, data);
            if (mec.Status)
            {
                int intFpc = mec.FPCount;
                int intFnc = mec.FNCount;
                tbFN.Text           = intFnc.ToString();
                tbFP.Text           = intFpc.ToString();
                txbSpecificity.Text = mec.Specificity.ToString();
                txbSensitivity.Text = mec.Sensitivity.ToString();
                txbAccuracy.Text    = mec.Accuracy.ToString();
            }
            else
            {
                string msg = "Data Error: " + mec.Message.ToString();
                MessageBox.Show(msg);
                return;
            }

            LineItem curve2 = zedGraphControl1.GraphPane.CurveList[1] as LineItem;
            LineItem curve3 = zedGraphControl1.GraphPane.CurveList[2] as LineItem;

            if ((curve2 != null) && (curve3 != null))
            {
                curve2.Line.IsVisible = false;
                curve3.Line.IsVisible = false;

                // Get the PointPairList
                IPointListEdit list2 = curve2.Points as IPointListEdit;
                list2.Clear();
                //mikec want the thresholds crossing, thus the "-1", "+1"
                list2.Add(minX - 1, dblDecisionThreshold);
                list2.Add(maxX + 1, dblDecisionThreshold);
                curve2.Line.IsVisible = true;

                // Get the PointPairList
                //mikec want the thresholds crossing, thus the "-1", "+1"
                IPointListEdit list3 = curve3.Points as IPointListEdit;
                list3.Clear();
                list3.Add(dblMandateThreshold, minY - 1);
                list3.Add(dblMandateThreshold, maxY + 1);
                curve3.Line.IsVisible = true;
            }

            // Keep the X scale at a rolling 30 second interval, with one
            // major step between the max X value and the end of the axis
            Scale xScale = zedGraphControl1.GraphPane.XAxis.Scale;

            if (data[data.Count - 1][0] > xScale.Max - xScale.MajorStep)
            {
            }

            GraphPane zgc1pane = zedGraphControl1.GraphPane;

            zgc1pane.XAxis.Cross = 0;

            // Make sure the Y axis is rescaled to accommodate actual data
            zedGraphControl1.AxisChange();
            // Force a redraw
            zedGraphControl1.Invalidate();
            zedGraphControl1.Refresh();
            Application.DoEvents();
        }
Example #17
0
        public void clearLines()
        {
            if (zed1.GraphPane.CurveList.Count <= 0)
            {
                return;
            }


            LineItem curve1 = zed1.GraphPane.CurveList[0] as LineItem;

            if (curve1 == null)
            {
                return;
            }

            IPointListEdit list1 = curve1.Points as IPointListEdit;

            if (list1 != null)
            {
                list1.Clear();
            }


            LineItem curve2 = zed1.GraphPane.CurveList[1] as LineItem;

            if (curve2 == null)
            {
                return;
            }


            IPointListEdit list2 = curve2.Points as IPointListEdit;

            if (list2 != null)
            {
                list2.Clear();
            }

            LineItem curve3 = zed1.GraphPane.CurveList[2] as LineItem;

            if (curve3 == null)
            {
                return;
            }

            IPointListEdit list3 = curve3.Points as IPointListEdit;

            if (list3 != null)
            {
                list3.Clear();
            }


            LineItem curve4 = zed1.GraphPane.CurveList[3] as LineItem;

            if (curve4 == null)
            {
                return;
            }

            IPointListEdit list4 = curve4.Points as IPointListEdit;

            if (list4 != null)
            {
                list4.Clear();
            }

            zed1.Invalidate();
        }
Example #18
0
        //---Methode zum Zeichnen des neuen Samples---
        void Draw_Graph(int[] lead)
        {
            // temp[0] = lead 2
            // temp[1] = lead 3
            // temp[2] = V1
            // temp[3] = V2
            // temp[4] = V3
            // temp[5] = V4
            // temp[6] = V5
            // temp[7] = V6
            // temp[8] = lead 1
            // temp[9] = aVR
            // temp[10] = aVL
            // temp[11] = aVR


            double[] temp = new Double[12];

            int abstand = 100;

            MethodInvoker gettrackbar2 = delegate
            {
                abstand = trackBar2.Value;
            };

            Invoke(gettrackbar2);



            //Lead2
            LineItem       curve = GraphWindow.GraphPane.CurveList[1] as LineItem;
            IPointListEdit list  = curve.Points as IPointListEdit;

            circular_buffer0[zeiger[0]] = lead[0];
            zeiger[0] = (zeiger[0] + 1) % 12;
            for (i = 0; i < 12; i++)
            {
                temp[0] += (b[i] * circular_buffer0[(zeiger[0] + i) % 12]);
            }
            if (Lead2Enabled.Checked == true)
            {
                list.Add(zeit, (temp[0] - abstand));
            }
            else
            {
                list.Clear();
            }


            //Lead3
            curve = GraphWindow.GraphPane.CurveList[2] as LineItem;
            list  = curve.Points as IPointListEdit;
            circular_buffer1[zeiger[1]] = lead[1];
            zeiger[1] = (zeiger[1] + 1) % 12;
            for (i = 0; i < 12; i++)
            {
                temp[1] += (b[i] * circular_buffer1[(zeiger[1] + i) % 12]);
            }
            if (Lead3Enabled.Checked == true)
            {
                list.Add(zeit, (temp[1] - (2 * abstand)));
            }
            else
            {
                list.Clear();
            }

            //Lead1
            curve   = GraphWindow.GraphPane.CurveList[0] as LineItem;
            list    = curve.Points as IPointListEdit;
            temp[8] = (temp[0] - temp[1]);

            if (Lead1Enabled.Checked == true)
            {
                list.Add(zeit, temp[8]);
            }
            else
            {
                list.Clear();
            }

            //V1
            curve = GraphWindow.GraphPane.CurveList[6] as LineItem;
            list  = curve.Points as IPointListEdit;
            if (V1Enabled.Checked == true)
            {
                circular_buffer2[zeiger[2]] = lead[2];
                zeiger[2] = (zeiger[2] + 1) % 12;
                for (i = 0; i < 12; i++)
                {
                    temp[2] += (b[i] * circular_buffer2[(zeiger[2] + i) % 12]);
                }
                list.Add(zeit, (temp[2] - (6 * abstand)));
            }
            else
            {
                list.Clear();
            }

            //V2
            curve = GraphWindow.GraphPane.CurveList[7] as LineItem;
            list  = curve.Points as IPointListEdit;
            if (V2Enabled.Checked == true)
            {
                circular_buffer3[zeiger[3]] = lead[3];
                zeiger[3] = (zeiger[3] + 1) % 12;
                for (i = 0; i < 12; i++)
                {
                    temp[3] += (b[i] * circular_buffer3[(zeiger[3] + i) % 12]);
                }
                list.Add(zeit, (temp[3] - (7 * abstand)));
            }
            else
            {
                list.Clear();
            }

            //Beat detection
            if (temp[3] <= (-2000))
            {
                MethodInvoker beater = delegate
                {
                    label28.Visible = true;
                    ekg1.LED_On();
                };
                Invoke(beater);


                if (!beat)
                {
                    Thread piep_thread = new Thread(delegate() { piep(2000, 100); });
                    piep_thread.IsBackground = true;
                    piep_thread.Start();
                    beat = true;
                }
            }
            else
            {
                MethodInvoker nobeat = delegate
                {
                    label28.Visible = false;
                    ekg1.LED_Off();
                };
                Invoke(nobeat);
                beat = false;
            }

            //V3
            curve = GraphWindow.GraphPane.CurveList[8] as LineItem;
            list  = curve.Points as IPointListEdit;
            if (V3Enabled.Checked == true)
            {
                circular_buffer4[zeiger[4]] = lead[4];
                zeiger[4] = (zeiger[4] + 1) % 12;
                for (i = 0; i < 12; i++)
                {
                    temp[4] += (b[i] * circular_buffer4[(zeiger[4] + i) % 12]);
                }
                list.Add(zeit, (temp[4] - (8 * abstand)));
            }
            else
            {
                list.Clear();
            }


            //V4
            curve = GraphWindow.GraphPane.CurveList[9] as LineItem;
            list  = curve.Points as IPointListEdit;
            if (V4Enabled.Checked == true)
            {
                circular_buffer5[zeiger[5]] = lead[5];
                zeiger[5] = (zeiger[5] + 1) % 12;
                for (i = 0; i < 12; i++)
                {
                    temp[5] += (b[i] * circular_buffer5[(zeiger[5] + i) % 12]);
                }
                list.Add(zeit, (temp[5] - (9 * abstand)));
            }
            else
            {
                list.Clear();
            }

            //V5
            curve = GraphWindow.GraphPane.CurveList[10] as LineItem;
            list  = curve.Points as IPointListEdit;
            if (V5Enabled.Checked == true)
            {
                circular_buffer6[zeiger[6]] = lead[6];
                zeiger[6] = (zeiger[6] + 1) % 12;
                for (i = 0; i < 12; i++)
                {
                    temp[6] += (b[i] * circular_buffer6[(zeiger[6] + i) % 12]);
                }
                list.Add(zeit, (temp[6] - (10 * abstand)));
            }
            else
            {
                list.Clear();
            }



            //V6
            curve = GraphWindow.GraphPane.CurveList[11] as LineItem;
            list  = curve.Points as IPointListEdit;
            if (V6Enabled.Checked == true)
            {
                circular_buffer7[zeiger[7]] = lead[7];
                zeiger[7] = (zeiger[7] + 1) % 12;
                for (i = 0; i < 12; i++)
                {
                    temp[7] += (b[i] * circular_buffer7[(zeiger[7] + i) % 12]);
                }
                list.Add(zeit, (temp[7] - (11 * abstand)));
            }
            else
            {
                list.Clear();
            }



            //aVR
            curve   = GraphWindow.GraphPane.CurveList[3] as LineItem;
            list    = curve.Points as IPointListEdit;
            temp[9] = (-(temp[0] + temp[1])) / 2;

            if (aVREnabled.Checked == true)
            {
                list.Add(zeit, (temp[9] - (3 * abstand)));
            }
            else
            {
                list.Clear();
            }

            //aVL
            curve    = GraphWindow.GraphPane.CurveList[4] as LineItem;
            list     = curve.Points as IPointListEdit;
            temp[10] = ((temp[0] - temp[1]) / 2);

            if (aVLEnabled.Checked == true)
            {
                list.Add(zeit, (temp[10] - (4 * abstand)));
            }
            else
            {
                list.Clear();
            }


            //aVF
            curve    = GraphWindow.GraphPane.CurveList[5] as LineItem;
            list     = curve.Points as IPointListEdit;
            temp[11] = ((temp[1] + temp[2]) / 2);

            if (aVFEnabled.Checked == true)
            {
                list.Add(zeit, (temp[11] - (5 * abstand)));
            }
            else
            {
                list.Clear();
            }

            //Wenn Autoscroll aktiv ist
            if (checkBox6.Checked == true)
            {
                GraphAutoSize();
            }
            else
            {
                GraphWindow.AxisChange();
                GraphWindow.Invalidate();
            }

            if (recording)
            {
                //get the Data for one row
                CsvRow row = new CsvRow();
                row.Add(String.Format("{0}", SampleCount));  //#
                row.Add(String.Format(temp[8].ToString()));  //Lead 1
                row.Add(String.Format(temp[0].ToString()));  //Lead 2
                row.Add(String.Format(temp[1].ToString()));  //Lead 3
                row.Add(String.Format(temp[9].ToString()));  //aVR
                row.Add(String.Format(temp[10].ToString())); //aVL
                row.Add(String.Format(temp[11].ToString())); //aVF
                row.Add(String.Format(temp[2].ToString()));  //V1
                row.Add(String.Format(temp[3].ToString()));  //V2
                row.Add(String.Format(temp[4].ToString()));  //V3
                row.Add(String.Format(temp[5].ToString()));  //V4
                row.Add(String.Format(temp[6].ToString()));  //V5
                row.Add(String.Format(temp[7].ToString()));  //V6

                //write the row in the buffer
                writer.WriteRow(row);
                writer.Flush();

                SampleCount++;

                /*
                 * //Safe to file
                 * if (SampleCount < 10)
                 * {
                 *  for (i = 0; i < 12; i++)
                 *  {
                 *      SampleSaveBuffer[SampleCount, i] = temp[i];
                 *
                 *  }
                 *  SampleCount++;
                 * }
                 * else
                 * {
                 *
                 *  for (int i = 0; i < 10; i++)
                 *  {
                 *      //get the Data for one row
                 *      CsvRow row = new CsvRow();
                 *      row.Add(String.Format("{0}", i)); //#
                 *      row.Add(String.Format(SampleSaveBuffer[i, 8].ToString())); //Lead 1
                 *      row.Add(String.Format(SampleSaveBuffer[i, 0].ToString())); //Lead 2
                 *      row.Add(String.Format(SampleSaveBuffer[i, 1].ToString())); //Lead 3
                 *      row.Add(String.Format(SampleSaveBuffer[i, 9].ToString())); //aVR
                 *      row.Add(String.Format(SampleSaveBuffer[i, 10].ToString()));//aVL
                 *      row.Add(String.Format(SampleSaveBuffer[i, 11].ToString()));//aVF
                 *      row.Add(String.Format(SampleSaveBuffer[i, 2].ToString())); //V1
                 *      row.Add(String.Format(SampleSaveBuffer[i, 3].ToString())); //V2
                 *      row.Add(String.Format(SampleSaveBuffer[i, 4].ToString())); //V3
                 *      row.Add(String.Format(SampleSaveBuffer[i, 5].ToString())); //V4
                 *      row.Add(String.Format(SampleSaveBuffer[i, 6].ToString())); //V5
                 *      row.Add(String.Format(SampleSaveBuffer[i, 7].ToString())); //V6
                 *
                 *      //write the row in the buffer
                 *      writer.WriteRow(row);
                 *  }
                 *
                 *  SampleCount = 0;
                 * }*/
            }
        }
Example #19
0
        // ------------------  CHARTING ROUTINES ---------------------

        // Set up the chart
        public void SetupChart()
        {
            MasterPane masterPane = chartControl.MasterPane;

            masterPane.PaneList.Clear();

            // get a reference to the GraphPane

            _temperaturePane = new GraphPane(new Rectangle(5, 5, 890, 350),
                                             "Temperature controller",
                                             "Time (s)",
                                             "Temperature (C)");
            masterPane.Add(_temperaturePane);

            //var temperaturePane = chartControl.GraphPane;

            // Set the Titles
            //temperaturePane.Title.Text = "Temperature controller";
            //temperaturePane.XAxis.Title.Text = "Time (s)";
            //temperaturePane.YAxis.Title.Text = "Temperature (C)";

            // Create data arrays for rolling points
            _analog1List = new RollingPointPairList(3000);
            _analog3List = new RollingPointPairList(3000);
            _analog1List.Clear();
            _analog3List.Clear();

            // Create a smoothened red curve for the current temperature
            LineItem myCurve1 = _temperaturePane.AddCurve("Current temperature", _analog1List, Color.Red, SymbolType.None);

            myCurve1.Line.Width         = 2;
            myCurve1.Line.IsSmooth      = true;
            myCurve1.Line.SmoothTension = 0.2f;


            // Create a smoothened blue curve for the goal temperature
            LineItem myCurve3 = _temperaturePane.AddCurve("Goal temperature", _analog3List, Color.Blue, SymbolType.None);

            myCurve3.Line.Width         = 2;
            myCurve3.Line.IsSmooth      = true;
            myCurve3.Line.SmoothTension = 0.2f;
            // Tell ZedGraph to re-calculate the axes since the data have changed
            chartControl.AxisChange();

            _heaterPane = new GraphPane(new Rectangle(5, 360, 890, 250),
                                        null,
                                        null,
                                        null);
            masterPane.Add(_heaterPane);

            _heaterList    = new RollingPointPairList(3000);
            _heaterPwmList = new RollingPointPairList(3000);
            _heaterList.Clear();
            _heaterPwmList.Clear();

            // Create a red curve for the heater value
            LineItem heaterCurve = _heaterPane.AddCurve(null, _heaterList, Color.YellowGreen, SymbolType.None);

            heaterCurve.Line.Width    = 2;
            heaterCurve.Line.IsSmooth = false;

            // Create a red curve for the current heater pwm value
            LineItem heaterPwmCurve = _heaterPane.AddCurve(null, _heaterPwmList, Color.Blue, SymbolType.None);

            heaterPwmCurve.Line.Width    = 2;
            heaterPwmCurve.Line.IsSmooth = false;

            SetChartScale(0);
        }