Ejemplo n.º 1
0
        private void MenuButtonClicked(MControls.ImageTextButton button, String id)
        {
            //主页面按钮被点击
            if (id == "1")
            {
                DisplayPage(MainPageIns);
            }
            //数据显示页面按钮被点击
            else if (id == "2")
            {
                DisplayPage(DatasDisplayPageIns);
            }
            //串口控制页面按钮被点击
            else if (id == "3")
            {
                DisplayPage(ComsControlPageIns);
            }
            //控制台页面按钮被点击
            else if (id == "4")
            {
                DisplayPage(ConsolePageIns);
            }


            //将之前活跃的按钮设置为不活跃
            if (NowActiveButton != null)
            {
                NowActiveButton.DisActive();
            }

            NowActiveButton = button;
        }
Ejemplo n.º 2
0
        private void ComsSelectButtonClick(ImageTextButton sender, String id)
        {
            if (NowSelectComs != null && NowSelectComs != sender)
            {
                NowSelectComs.DisActive();
            }

            NowSelectComs = sender;

            //串口名字选择赋值
            SelectPara.ComName = NowSelectComs.MButtonText;
        }
Ejemplo n.º 3
0
        private void ComControler_DatasCollectFinishedEvent(Dictionary <int, RecordModel> model)
        {
            //并没有选择任何器件,则没有任何影响
            if (NowSelectDeviceButton == null)
            {
                return;
            }

            //获取刚刚获得的对应器件的信息
            RecordModel data = model[NowSelectDeviceID];


            //添加新的按钮
            ImageTextButton onceButton = new ImageTextButton();

            onceButton.Style = (Style)this.Resources["MComSelectTButtonStyle"];
            onceButton.SetIDAndClick(OnceDataButtonClick, data.FileName);
            onceButton.MButtonText         = data.TimeString;
            onceButton.ButtonText.FontSize = 10;
            OnceDataOfDeviceSelectSP.Children.Insert(0, onceButton);

            //获取数据
            OneDeviceDatasModel one = OneDeviceDatasModel.CreateModelFromXMLFile(data.FileName);

            //添加数据到对应的曲线上
            for (int counterForData = 0; counterForData < one.Count(); counterForData++)
            {
                DataPoint lightPoint = new DataPoint();
                lightPoint.YValue = one.LightIntensity[counterForData];
                TotalLightDS.DataPoints.Add(lightPoint);


                DataPoint powerPoint = new DataPoint();
                powerPoint.YValue = one.PowerFactor[counterForData];
                TotalPowerFactorDS.DataPoints.Add(powerPoint);

                DataPoint voltagePoint = new DataPoint();
                voltagePoint.YValue = one.Voltage[counterForData];
                TotalVoltageDS.DataPoints.Add(voltagePoint);

                DataPoint something1Point = new DataPoint();
                something1Point.YValue = one.Somethings1[counterForData];
                TotalSomethings1DS.DataPoints.Add(something1Point);

                DataPoint something2Point = new DataPoint();
                something2Point.YValue = one.Somethings2[counterForData];
                TotalSomethings2DS.DataPoints.Add(something2Point);
            }
        }
Ejemplo n.º 4
0
        public DatasDisplayPage()
        {
            InitializeComponent();

            for (int counter = 0; counter <= 19; counter++)
            {
                ImageTextButton deviceButton = new ImageTextButton();
                deviceButton.Style = (Style)this.Resources["MComSelectTButtonStyle"];
                deviceButton.SetIDAndClick(DeviceSelectButtonClick, counter.ToString());
                deviceButton.MButtonText = counter.ToString();
                deviceButton.ButtonText.TextAlignment = TextAlignment.Center;
                DeviceIDSelectSP.Children.Add(deviceButton);
            }

            ComControler.DatasCollectFinishedEvent += ComControler_DatasCollectFinishedEvent;
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="id">对应数据的文件名</param>
        private void OnceDataButtonClick(ImageTextButton sender, String id)
        {
            if (NowSelectOnceDataButton != null && NowSelectOnceDataButton != sender)
            {
                NowSelectOnceDataButton.DisActive();
            }

            NowSelectOnceDataButton = sender;


            //如果之前某次数据显示表中有数据,则将其去除
            if (OnceLightDS != null)
            {
                OnceDataChart.Series.Remove(OnceLightDS);
                OnceDataChart.Series.Remove(OncePowerFactorDS);
                OnceDataChart.Series.Remove(OnceVoltageDS);
                OnceDataChart.Series.Remove(OnceSomethings1DS);
                OnceDataChart.Series.Remove(OnceSomethings2DS);
            }

            //创建新的数据集
            OnceLightDS            = new DataSeries();
            OnceLightDS.Color      = LightLineBrush;
            OnceLightDS.LegendText = "光照强度";
            OnceLightDS.RenderAs   = RenderAs.Spline;

            OncePowerFactorDS            = new DataSeries();
            OncePowerFactorDS.Color      = PowerFactorLineBrush;
            OncePowerFactorDS.LegendText = "功率因数";
            OncePowerFactorDS.RenderAs   = RenderAs.Spline;

            OnceVoltageDS            = new DataSeries();
            OnceVoltageDS.Color      = VoltageLineBrush;
            OnceVoltageDS.LegendText = "电压";
            OnceVoltageDS.RenderAs   = RenderAs.Spline;

            OnceSomethings1DS            = new DataSeries();
            OnceSomethings1DS.Color      = Something1LineBrush;
            OnceSomethings1DS.LegendText = "Somethings1";
            OnceSomethings1DS.RenderAs   = RenderAs.Spline;

            OnceSomethings2DS            = new DataSeries();
            OnceSomethings2DS.Color      = Something2LineBrush;
            OnceSomethings2DS.LegendText = "Somethings2";
            OnceSomethings2DS.RenderAs   = RenderAs.Spline;

            //获得模型数据
            OneDeviceDatasModel model = OneDeviceDatasModel.CreateModelFromXMLFile(id);

            for (int counter = 0; counter < model.Count(); counter++)
            {
                DataPoint lightPoint = new DataPoint();
                lightPoint.YValue = model.LightIntensity[counter];
                OnceLightDS.DataPoints.Add(lightPoint);


                DataPoint powerPoint = new DataPoint();
                powerPoint.YValue = model.PowerFactor[counter];
                OncePowerFactorDS.DataPoints.Add(powerPoint);

                DataPoint voltagePoint = new DataPoint();
                voltagePoint.YValue = model.Voltage[counter];
                OnceVoltageDS.DataPoints.Add(voltagePoint);

                DataPoint something1Point = new DataPoint();
                something1Point.YValue = model.Somethings1[counter];
                OnceSomethings1DS.DataPoints.Add(something1Point);

                DataPoint something2Point = new DataPoint();
                something2Point.YValue = model.Somethings2[counter];
                OnceSomethings2DS.DataPoints.Add(something2Point);
            }


            OnceDataChart.Series.Add(OnceLightDS);
            OnceDataChart.Series.Add(OncePowerFactorDS);
            OnceDataChart.Series.Add(OnceVoltageDS);
            OnceDataChart.Series.Add(OnceSomethings1DS);
            OnceDataChart.Series.Add(OnceSomethings2DS);
        }
Ejemplo n.º 6
0
        /*
         * private void CreateChart()
         * {
         *
         *  DataSeries dataSeries = new DataSeries();
         *
         *  DTotalChart.Series.Add(dataSeries);
         *
         *  dataSeries.RenderAs = RenderAs.Spline;
         *
         *  // Number of DataPoints to be generated
         *  int numberOfDataPoints = 10;
         *
         *  // To set the YValues of DataPoint
         *  Random random = new Random();
         *
         *  // Loop and add a few DataPoints
         *  for (int loopIndex = 0; loopIndex < numberOfDataPoints; loopIndex++)
         *  {
         *
         *      // Create a DataPoint
         *      DataPoint dataPoint = new DataPoint();
         *
         *      dataPoint.XValue = loopIndex;
         *      // Set the YValue using random number
         *      dataPoint.YValue = random.Next(1, 100);
         *
         *      // Add DataPoint to DataSeries
         *      dataSeries.DataPoints.Add(dataPoint);
         *  }
         * }*/

        //器件选择变换
        private void DeviceSelectButtonClick(ImageTextButton sender, String id)
        {
            if (NowSelectDeviceButton != null && NowSelectDeviceButton != sender)
            {
                NowSelectDeviceButton.DisActive();
            }

            NowSelectDeviceButton = sender;
            NowSelectDeviceID     = int.Parse(id);

            //从0 -》 count , 时间为最接近现在 到 最久远
            //故而显示按钮排列 0 -> COUNT , 而total数据添加,从 count -> 0
            List <RecordModel> records = RecordDBControler.UnityIns.ReadSpecialDeviceRecord(true, NowSelectDeviceID);

            //如果之前某次数据显示表中有数据,则将其去除
            if (OnceLightDS != null)
            {
                OnceDataChart.Series.Remove(OnceLightDS);
                OnceDataChart.Series.Remove(OncePowerFactorDS);
                OnceDataChart.Series.Remove(OnceVoltageDS);
                OnceDataChart.Series.Remove(OnceSomethings1DS);
                OnceDataChart.Series.Remove(OnceSomethings2DS);
            }

            //如果之前总数据表中有数据,则将其去除
            if (TotalLightDS != null)
            {
                DTotalChart.Series.Remove(TotalLightDS);
                DTotalChart.Series.Remove(TotalPowerFactorDS);
                DTotalChart.Series.Remove(TotalVoltageDS);
                DTotalChart.Series.Remove(TotalSomethings1DS);
                DTotalChart.Series.Remove(TotalSomethings2DS);
            }

            //去除某次数据SP中所有的子元素
            OnceDataOfDeviceSelectSP.Children.Clear();
            NowSelectOnceDataButton = null;

            for (int counter = 0; counter < records.Count; counter++)
            {
                ImageTextButton onceButton = new ImageTextButton();
                onceButton.Style = (Style)this.Resources["MComSelectTButtonStyle"];
                onceButton.SetIDAndClick(OnceDataButtonClick, records[counter].FileName);
                onceButton.MButtonText         = records[counter].TimeString;
                onceButton.ButtonText.FontSize = 10;
                OnceDataOfDeviceSelectSP.Children.Add(onceButton);
            }

            //创建新的数据集
            TotalLightDS            = new DataSeries();
            TotalLightDS.Color      = LightLineBrush;
            TotalLightDS.LegendText = "光照强度";
            TotalLightDS.RenderAs   = RenderAs.Spline;

            TotalPowerFactorDS            = new DataSeries();
            TotalPowerFactorDS.Color      = PowerFactorLineBrush;
            TotalPowerFactorDS.LegendText = "功率因数";
            TotalPowerFactorDS.RenderAs   = RenderAs.Spline;

            TotalVoltageDS            = new DataSeries();
            TotalVoltageDS.Color      = VoltageLineBrush;
            TotalVoltageDS.LegendText = "电压";
            TotalVoltageDS.RenderAs   = RenderAs.Spline;

            TotalSomethings1DS            = new DataSeries();
            TotalSomethings1DS.Color      = Something1LineBrush;
            TotalSomethings1DS.LegendText = "Somethings1";
            TotalSomethings1DS.RenderAs   = RenderAs.Spline;

            TotalSomethings2DS            = new DataSeries();
            TotalSomethings2DS.Color      = Something2LineBrush;
            TotalSomethings2DS.LegendText = "Somethings2";
            TotalSomethings2DS.RenderAs   = RenderAs.Spline;

            //添加所有的数据
            for (int counter = records.Count - 1; counter >= 0; counter--)
            {
                //记录的模型则是从0 -> count,是最早采集->最晚采集
                OneDeviceDatasModel model = OneDeviceDatasModel.CreateModelFromXMLFile(records[counter].FileName);
                for (int counterForData = 0; counterForData < model.Count(); counterForData++)
                {
                    DataPoint lightPoint = new DataPoint();
                    lightPoint.YValue = model.LightIntensity[counterForData];
                    TotalLightDS.DataPoints.Add(lightPoint);


                    DataPoint powerPoint = new DataPoint();
                    powerPoint.YValue = model.PowerFactor[counterForData];
                    TotalPowerFactorDS.DataPoints.Add(powerPoint);

                    DataPoint voltagePoint = new DataPoint();
                    voltagePoint.YValue = model.Voltage[counterForData];
                    TotalVoltageDS.DataPoints.Add(voltagePoint);

                    DataPoint something1Point = new DataPoint();
                    something1Point.YValue = model.Somethings1[counterForData];
                    TotalSomethings1DS.DataPoints.Add(something1Point);

                    DataPoint something2Point = new DataPoint();
                    something2Point.YValue = model.Somethings2[counterForData];
                    TotalSomethings2DS.DataPoints.Add(something2Point);
                }
            }

            //添加所有的点集到总集
            DTotalChart.Series.Add(TotalLightDS);
            DTotalChart.Series.Add(TotalVoltageDS);
            DTotalChart.Series.Add(TotalPowerFactorDS);
            DTotalChart.Series.Add(TotalSomethings1DS);
            DTotalChart.Series.Add(TotalSomethings2DS);
        }
Ejemplo n.º 7
0
        private void InsideSecondTimer_Tick(object sender, EventArgs e)
        {
            List <string> names = ComNamesDispose.GetComNames();

            //上次选择的串口已经消失 , 则去除
            //不需要担心串口的开关问题,其已经由事件解决
            if (NowSelectComs != null && !names.Contains(NowSelectComs.MButtonText))
            {
                NowSelectComs.DisActive();
                ComsSelectSP.Children.Remove(NowSelectComs);
                TotalPorts.Remove(NowSelectComs);
                NowSelectComs = null;

                //如果在串口消失即拔出串口的时候,串口已经打开了,则自动关闭
                if (ComControler.UnityIns.IsPortOpen())
                {
                    ComControler.UnityIns.PortClosed();

                    //设置为串口已经关闭,并且修改图标
                    IsPortOpen = false;
                    ComOpenOrCloseTB.ButtonIcon = MahApps.Metro.IconPacks.PackIconMaterialKind.Play;

                    ComsSelectSP.IsEnabled = true;
                    StopBitsSP.IsEnabled   = true;
                    ParitySP.IsEnabled     = true;
                    HandshakeSP.IsEnabled  = true;
                    BandRateSP.IsEnabled   = true;
                }
            }

            //去除已经不存在的串口
            List <int> removeIndex = new List <int>();

            for (int counter = 0; counter < TotalPorts.Count; counter++)
            {
                if (!names.Contains(TotalPorts[counter].MButtonText))
                {
                    removeIndex.Add(counter);
                }
            }

            foreach (int index in removeIndex)
            {
                TotalPorts.RemoveAt(index);
                ComsSelectSP.Children.RemoveAt(index);
            }


            List <string> nowDisplayComs = new List <string>();

            foreach (var port in TotalPorts)
            {
                nowDisplayComs.Add(port.MButtonText);
            }

            foreach (var name in names)
            {
                //如果出现了新的串口,将其添加
                if (!nowDisplayComs.Contains(name))
                {
                    ImageTextButton comButton = new ImageTextButton();
                    comButton.Style = (Style)this.Resources["MComSelectTButtonStyle"];
                    comButton.SetIDAndClick(ComsSelectButtonClick, name);
                    comButton.MButtonText = name;

                    ComsSelectSP.Children.Add(comButton);
                    TotalPorts.Add(comButton);
                }
            }
        }