예제 #1
0
        /// <summary>
        /// copy data from TimeSeries.Series into ZedGraph CurveItem
        /// </summary>
        /// <param name="s"></param>
        /// <param name="tSeries"></param>
        void FillTimeSeries(Series s, CurveItem tSeries)
        {
            if (s.Count == 0)
            {
                return;
            }

            pane.XAxis.Type = AxisType.Date;

            int sz = s.Count;

            for (int i = 0; i < sz; i++)
            {
                Point  pt = s[i];
                double x  = pt.DateTime.ToOADate();

                if (!pt.IsMissing)
                {
                    tSeries.AddPoint(x, pt.Value);
                }
                else
                {
                    tSeries.AddPoint(x, Double.NaN);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// copy data from TimeSeries.Series into ZedGraph CurveItem
        /// </summary>
        /// <param name="s"></param>
        /// <param name="tSeries"></param>
        void FillTimeSeries(Series s, CurveItem tSeries)
        {
            if (s.Count == 0)
            {
                return;
            }

            var pane = this.chart1.GraphPane;

            pane.XAxis.Type = AxisType.Date;

            double avg = TimeSeries.Math.AverageOfSeries(s);
            int    sz  = s.Count;

            for (int i = 0; i < sz; i++)
            {
                Point  pt = s[i];
                double x  = pt.DateTime.ToOADate();

                if (!pt.IsMissing)
                {
                    tSeries.AddPoint(x, pt.Value);
                }
                else
                {
                    //list.Add(x, avg, System.Drawing.Color.Transparent);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// copy data from TimeSeries.Series into ZedGraph CurveItem
        /// </summary>
        /// <param name="s"></param>
        /// <param name="tSeries"></param>
        void FillTimeSeries(DataTable table, CurveItem tSeries)
        {
            int sz = table.Rows.Count;

            if (sz == 0)
            {
                return;
            }

            var pane = this.chart1.GraphPane;

            pane.XAxis.Type = AxisType.Date;
            var    columnName = table.Columns[1].ColumnName;
            double avg        = AverageOfColumn(table, columnName);

            for (int i = 0; i < sz; i++)
            {
                DateTime date = (DateTime)table.Rows[i][0];

                if (table.Rows[i][columnName] != System.DBNull.Value)
                {
                    double val = Convert.ToDouble(table.Rows[i][columnName]);
                    tSeries.AddPoint(date.ToOADate(), val);
                }
                else
                {
                    //list.Add(x, avg, System.Drawing.Color.Transparent);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Handle the timer update
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tmrUpdate_Tick(object sender, EventArgs e)
        {
            //If our simulator is paused, don't add points
            if (Data_Integration.SimulatorStatus != MacomberMapCommunications.Messages.EMS.MM_Simulation_Time.enumSimulationStatus.Running || Data_Integration.CurrentTime == LastTime)
            {
                return;
            }

            LastTime = Data_Integration.CurrentTime;
            float NewValue = 0;

            foreach (MM_Element Elem in Elements)
            {
                float CurVal = FieldToCheck != null ? (float)FieldToCheck.GetValue(Elem) : (float)PropertyToCheck.GetValue(Elem);
                if (!float.IsNaN(CurVal))
                {
                    NewValue += CurVal;
                }
            }

            TrackingCurve.AddPoint(ZedGraph.XDate.DateTimeToXLDate(LastTime), NewValue);
            zgGraph.AxisChange();

            if (chkMax.Checked)
            {
                zgGraph.GraphPane.YAxis.Scale.Max = (double)nudMax.Value;
            }
            else
            {
                nudMax.Value = (decimal)zgGraph.GraphPane.YAxis.Scale.Max;
            }
            if (chkMin.Checked)
            {
                zgGraph.GraphPane.YAxis.Scale.Min = (double)nudMin.Value;
            }
            else
            {
                nudMin.Value = (decimal)zgGraph.GraphPane.YAxis.Scale.Min;
            }

            ThresholdLine = new LineObj(Color.Green, zgGraph.GraphPane.XAxis.Scale.Min, BaseValue, zgGraph.GraphPane.XAxis.Scale.Max, BaseValue);
            zgGraph.GraphPane.GraphObjList.Add(ThresholdLine);

            //    .X2 = zgGraph.GraphPane.XAxis.Scale.Max;
            zgGraph.Invalidate();


            String NewText = (NewValue - BaseValue).ToString(NumberFormat);

            if (lblDeltaValue.Text != NewText)
            {
                lblDeltaValue.Text = NewText;
                LastValueChange    = DateTime.Now;
            }

            int Sec = Math.Min(255, (int)(DateTime.Now - LastValueChange).TotalSeconds * 6);

            lblDeltaValue.ForeColor = lblBaseValue.ForeColor = lblOperator.ForeColor = Color.FromArgb(Sec, 255, Sec);
        }
예제 #5
0
        /// <summary>
        /// Begin tracking our value
        /// </summary>
        public void BeginTracking()
        {
            BaseValue = 0;
            foreach (MM_Element Elem in Elements)
            {
                float CurVal = FieldToCheck != null ? (float)FieldToCheck.GetValue(Elem) : (float)PropertyToCheck.GetValue(Elem);
                if (!float.IsNaN(CurVal))
                {
                    BaseValue += CurVal;
                }
            }


            lblBaseValue.Text       = BaseValue.ToString(NumberFormat);
            lblDeltaValue.Text      = (0).ToString(NumberFormat);
            lblDeltaValue.ForeColor = Color.White;

            //Set our master panel
            GraphPane myMaster = zgGraph.GraphPane;

            myMaster.CurveList.Clear();
            myMaster.Title.IsVisible          = false;
            myMaster.Title.FontSpec.FontColor = Color.White;
            myMaster.Legend.Fill = myMaster.Fill = new Fill(Color.Black);
            myMaster.Legend.FontSpec.FontColor      = Color.White;
            myMaster.Legend.FontSpec.Fill           = new Fill(Color.Black);
            myMaster.Legend.IsVisible               = true;
            myMaster.Legend.Position                = LegendPos.TopCenter;
            myMaster.XAxis.Title.FontSpec.FontColor = Color.White;
            myMaster.YAxis.Title.FontSpec.FontColor = Color.White;
            myMaster.XAxis.MajorTic.Color           = Color.White;
            myMaster.XAxis.MinorTic.Color           = Color.White;
            myMaster.YAxis.MajorTic.Color           = Color.White;
            myMaster.YAxis.MinorTic.Color           = Color.White;
            myMaster.XAxis.MajorGrid.Color          = Color.White;
            myMaster.YAxis.MajorGrid.Color          = Color.White;
            myMaster.Chart.Fill                     = new Fill(Color.Black);
            myMaster.Chart.Border.Color             = Color.DarkGray;
            myMaster.XAxis.Scale.FontSpec.FontColor = Color.White;
            myMaster.YAxis.Scale.FontSpec.FontColor = Color.White;
            this.BorderStyle      = System.Windows.Forms.BorderStyle.None;
            lblOperator.TextAlign = ContentAlignment.MiddleCenter;
            zgGraph.GraphPane.Legend.IsVisible = false;
            zgGraph.GraphPane.XAxis.Title.Text = "Date/Time";
            zgGraph.GraphPane.XAxis.Type       = AxisType.Date;
            zgGraph.GraphPane.XAxis.IsVisible  = false;
            zgGraph.GraphPane.YAxis.IsVisible  = false;
            zgGraph.IsShowPointValues          = true;
            TrackingCurve = myMaster.AddCurve(Title, new PointPairList(), Color.White);
            TrackingCurve.AddPoint(ZedGraph.XDate.DateTimeToXLDate(LastTime = Data_Integration.CurrentTime), BaseValue);

            LastValueChange = DateTime.Now;
            zgGraph.AxisChange();

            ThresholdLine = new LineObj(Color.Green, zgGraph.GraphPane.XAxis.Scale.Min, BaseValue, zgGraph.GraphPane.XAxis.Scale.Max, BaseValue);
            zgGraph.GraphPane.GraphObjList.Add(ThresholdLine);

            zgGraph.Invalidate();
        }
예제 #6
0
 void UpdateHistogramValues(Histogram histogram, CurveItem values)
 {
     values.Clear();
     for (int i = 0; i < 256; i++)
     {
         values.AddPoint(i, histogram.QueryValue(i));
     }
 }
예제 #7
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (bFirst)
            {
                timer1.Interval = cycle;
                bFirst          = false;
            }

            int adr_grp    = 0;
            int adr_offset = 0;
            int adr;

            for (int i = 0; i < lstGrp.Items.Count; i++)
            {
                adr = Int32.Parse(lstGrp.Items[i].ToString());
                if (parentFrm.svr.FindPosintion(adr, ref adr_grp, ref adr_offset))
                {
                    CurveItem curve = gp.CurveList[i];
                    if (parentFrm.svr.m_nFunc > 1)
                    {
                        if (abUnsigned[i])
                        {
                            curve.AddPoint((double)(ticks++), (double)(ushort)parentFrm.svr.m_sValue[adr_grp][adr_offset]);
                        }
                        else
                        {
                            curve.AddPoint((double)(ticks++), (double)parentFrm.svr.m_sValue[adr_grp][adr_offset]);
                        }
                    }
                    else
                    {
                        if (parentFrm.svr.m_bValue[adr_grp][adr_offset])
                        {
                            curve.AddPoint((double)(ticks++), 1.0);
                        }
                        else
                        {
                            curve.AddPoint((double)(ticks++), 0.0);
                        }
                    }
                }
                zd.AxisChange();
                zd.Refresh();
            }
        }
        public void drawNextSpot_curve(int ID)
        {
            if (init_Curves)
            {
                initCurves();
                z = zedGraphControl1.GraphPane;
                zedGraphControl1.IsShowHScrollBar  = true;
                zedGraphControl1.IsAutoScrollRange = true;
                zedGraphControl1.AutoScroll        = true;
                init_Curves = false;
            }
            else
            {
                if (i == 20 && scrolltrack)// && scroll_handler)
                {
                    scrolltrack = false;
                    zedGraphControl1.Controls[0].Focus();
                    SendKeys.Send("{RIGHT}");
                }
                if (z.XAxis.Scale.Max > 20 && scroll_handler)
                {
                    double range = z.XAxis.Scale.Max - z.XAxis.Scale.Min;
                    z.XAxis.Scale.Max           = t[0, i, ID] + 5;//+10 to be in the middle
                    z.XAxis.Scale.Min           = z.XAxis.Scale.Max - range;
                    zedGraphControl1.ScrollMaxX = xvalue1;
                }

                if (ID > 3 || ID < 0)
                {
                    return;
                }
                if (ID == 0)
                {
                    curve0.AddPoint(t[0, i, ID], t[1, i, ID]);
                }
                if (ID == 1)
                {
                    curve1.AddPoint(t[0, i, ID], t[1, i, ID]);
                }
                if (ID == 2)
                {
                    curve2.AddPoint(t[0, i, ID], t[1, i, ID]);
                }
                if (ID == 3)
                {
                    curve3.AddPoint(t[0, i, ID], t[1, i, ID]);
                }



                zedGraphControl1.Refresh();
                zedGraphControl1.Invalidate();
            }
        }
예제 #9
0
 private void AddPoint(CurveItem curve, double x, double y)
 {
     if (x < _minXValue)
     {
         _minXValue = x;
     }
     if (x > _maxXValue)
     {
         _maxXValue = x;
     }
     if (y < _minYValue)
     {
         _minYValue = y;
     }
     if (y > _maxYValue)
     {
         _maxYValue = y;
     }
     curve.AddPoint(x, y);
 }
예제 #10
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            int col = 1;
            int row;

            WSMBS.Result sRes = WSMBS.Result.SUCCESS;
            WSMBT.Result tRes = WSMBT.Result.SUCCESS;

            switch (m_nCmdNo)
            {
            case 0:
                if (m_curInterface == 2)
                {
                    tRes = tcpip.ReadDiscreteInputs((byte)numStation.Value, m_nAddr, m_nLength, sw);
                }
                else
                {
                    sRes = serial.ReadDiscreteInputs((byte)numStation.Value, m_nAddr, m_nLength, sw);
                }
                break;

            case 1:
                if (m_curInterface == 2)
                {
                    tRes = tcpip.ReadCoils((byte)numStation.Value, m_nAddr, m_nLength, sw);
                }
                else
                {
                    sRes = serial.ReadCoils((byte)numStation.Value, m_nAddr, m_nLength, sw);
                }
                break;

            case 2:
                if (m_curInterface == 2)
                {
                    tRes = tcpip.ReadHoldingRegisters((byte)numStation.Value, m_nAddr, m_nLength, reg);
                }
                else
                {
                    sRes = serial.ReadHoldingRegisters((byte)numStation.Value, m_nAddr, m_nLength, reg);
                }
                break;

            case 3:
                if (m_curInterface == 2)
                {
                    tRes = tcpip.ReadInputRegisters((byte)numStation.Value, m_nAddr, m_nLength, reg);
                }
                else
                {
                    sRes = serial.ReadInputRegisters((byte)numStation.Value, m_nAddr, m_nLength, reg);
                }
                break;

            default:
                break;
            }

            nTx++;
            if (sRes != WSMBS.Result.SUCCESS || tRes != WSMBT.Result.SUCCESS)
            {
                picConn.Enabled = false;
                nFailCounter++;
            }
            else
            {
                byte[] rxbuf = new byte[256];
                int    n;
                if (m_curInterface == 2)
                {
                    n = tcpip.GetRxBuffer(rxbuf);
                }
                else
                {
                    n = serial.GetRxBuffer(rxbuf);
                }

                if (n != 0)
                {
                    string str = "";
                    for (int i = 0; i < n; i++)
                    {
                        str += string.Format("{0:X2} ", rxbuf[i]);
                        if (((i + 1) % 5) == 0)
                        {
                            str += "_ ";
                        }
                    }
                    labRecv.Text = str;
                }

                for (int i = 0; i < m_nLength; i++)
                {
                    row = i / 2;
                    gridData.Rows[row].Cells[col].Value = (m_nCmdNo > 1) ? reg[i].ToString(strFmtByte) : sw[i].ToString();
                    if (col == 1)
                    {
                        col = 3;
                    }
                    else
                    {
                        col = 1;
                    }
                }

                if (bExtend == 1)
                {
                    for (int i = 0; i < ptr_gp; i++)
                    {
                        CurveItem curve = gp.CurveList[i];
                        curve.AddPoint((double)(timeStart++), (double)reg[agpAdr[i]]);
                    }
                    zd.AxisChange();
                    zd.Refresh();
                }

                nRx++;
                nFailCounter    = 0;
                picConn.Enabled = true;
            }

            if (nFailCounter >= 3)
            {
                picConn.Enabled = false;
                timer1.Enabled  = false;
                if (m_curInterface == 2)
                {
                    labRecv.Text = "  Modbus总线通信错误,故障原因: " + tRes.ToString();
                }
                else
                {
                    labRecv.Text = "  Modbus总线通信错误,故障原因: " + sRes.ToString();
                }
                labRecv.ForeColor = Color.Red;
                nFailCounter      = 0;
            }

            labTx.Text = nTx.ToString();
            labRx.Text = nRx.ToString();
        }