Ejemplo n.º 1
0
        void state_dis_ini()
        {
            mw = this;
            #region  感参数部分
            chart1 = mainFGrid.Child as Chart;
            chart1.Legends[0].DockedToChartArea = "ChartArea1";
            chart1.Legends[0].BackColor         = System.Drawing.Color.Transparent;
            //从配置中加载参数
            chart1.Series.Clear();
            foreach (var item in config.dset)
            {
                commc.dset[item.name] = item;
                item.update_cb        = tn => { item.update_times = 10; };         //数据更新回调函数
                item.update_dis       = tn => { if (item.update_times > 0)
                                                {
                                                    item.update_times--;
                                                }
                };
                if (item.is_dis == false)
                {
                    continue;
                }
                CheckBox cb = new CheckBox();
                cb.Content    = item.name;
                cb.IsChecked  = item.is_cv;
                cb.Width      = 150;
                cb.Background = Brushes.LightCoral;
                cb.Margin     = new Thickness(2, 2, 2, 0);
                Series tmpserial = null;
                if (item.dtype == DestType.str)               //字符型的,不让选择曲线
                {
                    //cb.IsEnabled = false;
                }
                else                 //曲线型的
                {
                    tmpserial = new Series()
                    {
                        BorderWidth = 2,
                        ChartArea   = "ChartArea1",
                        ChartType   = SeriesChartType.Line,
                        //Color = System.Drawing.Color.Red,
                        Legend = "Legend1",
                        Name   = item.name,
                    };
                    chart1.Series.Add(tmpserial);
                    series_map[item.name] = tmpserial;
                }
                checkb_map[item.name] = cb;
                sp_measure.Children.Add(cb);
                item.update_cb += (delegate(string tn)               //数据更新回调函数
                {
                    try
                    {
                        var it = commc.dset[tn];
                        //it.update_times = 10;
                        if (it.dtype == DestType.val && (bool)cb.IsChecked) //若显示曲线
                        {
                            if (is_first == 1)                              //首次加入数据点,清除初始化点
                            {
                                clear_Click(null, null);
                                is_first = 0;
                            }
                            double d = double.Parse(it.val);
                            if (x_axis_id != "" && commc.dset.ContainsKey(x_axis_id))                            //若有索引列
                            {
                                if (tmpserial.Points.Count > 0 &&
                                    Math.Abs(tmpserial.Points[tmpserial.Points.Count - 1].XValue - x_tick) < 0.1f)                               //跟上次一样
                                {
                                    tmpserial.Points[tmpserial.Points.Count - 1].YValues[0] = d;
                                }
                                else
                                {
                                    tmpserial.Points.AddXY(x_tick, d);
                                }
                                if (tn == x_axis_id)
                                {
                                    x_tick++;
                                }
                            }
                            else                             //没有索引列,就用时间ms数作为x轴
                            {
                                tmpserial.Points.AddXY(ticks0 - st_ms, d);
                            }
                            if (tmpserial.Points.Count >= config.dis_data_len)
                            {
                                tmpserial.Points.RemoveAt(0);
                            }
                        }
                    }
                    catch { }
                });
                item.update_dis += (delegate(string tn)                  //数据更新回调函数
                {
                    var it = commc.dset[tn];
                    if (it.update_times > 0)                     //若有数据更新
                    {
                        //it.update_times--;
                        cb.Background = Brushes.LightGreen;
                        cb.Content = it.name + ":" + it.val;
                    }
                    else
                    {
                        cb.Background = Brushes.LightCoral;
                    }
                });
            }
            chart1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.DashDot;

            chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle     = ChartDashStyle.DashDot;
            chart1.ChartAreas[0].AxisY.MajorTickMark.LineDashStyle = ChartDashStyle.DashDot;

            chart1.ChartAreas[0].Axes[0].Maximum = 100;
            chart1.ChartAreas[0].Axes[0].Minimum = 0;
            chart1.ChartAreas[0].Axes[1].Maximum = 30;
            chart1.ChartAreas[0].Axes[1].Minimum = 20;
            //chart1.Series[0].Points.Add(0);
            //chart1.Series[0].Points.Add(0);
            if (config.svar_ui_h != 0)
            {
                row_para_dis.Height = new GridLength(config.svar_ui_h);
            }
            else
            {
                row_para_dis.Height = new GridLength((sp_measure.Children.Count + 4) / 5 * 20 + 27);
            }
            //sp_measure.Height = row_para_dis.Height.Value;
            #endregion
            #region 指令ui初始化
            CCmd_para.i_on  = new BitmapImage(new Uri("pack://application:,,,/pic/refresh_on.jpg"));
            CCmd_para.i_off = new BitmapImage(new Uri("pack://application:,,,/pic/refresh_off.jpg"));
            if (config.cmd_ui_w > 0)
            {
                colD_cmd_ui.Width = new GridLength(config.cmd_ui_w);
            }
            if (config.ctrl_cols == 3)           //若是3列排布的,把默认控制按钮的位置改一下
            {
                //通用控制按钮加一列
                grid_ctrl_bts.ColumnDefinitions.Add(new ColumnDefinition());
                //通用控制按钮位置修改
                System.Windows.Controls.Grid.SetRow(bt_refresh_uart, 0);
                System.Windows.Controls.Grid.SetColumn(bt_refresh_uart, 2);
                System.Windows.Controls.Grid.SetRow(checkb_rec_data, 1);
                System.Windows.Controls.Grid.SetColumn(checkb_rec_data, 0);
                System.Windows.Controls.Grid.SetRow(cb_fit_screen, 1);
                System.Windows.Controls.Grid.SetColumn(cb_fit_screen, 1);
                System.Windows.Controls.Grid.SetRow(bt_clear, 1);
                System.Windows.Controls.Grid.SetColumn(bt_clear, 2);
                //面板border加长
                System.Windows.Controls.Grid.SetColumnSpan(bd_dft_and_cfg, 3);
                //配置按钮面板加一列
                para_grid.ColumnDefinitions.Add(new ColumnDefinition());
            }
            int i = 0, j = 0;                                   //i行,j列
            foreach (var item in config.cmds)
            {                                                   //本来有一行
                commc.cmds[item.name] = item;
                int rownu = para_grid.RowDefinitions.Count - 1; //添加一行
                var v     = CCmd_Button.bt_factory(item.type, item, para_grid);
                v.ini(ref i, ref j);
                if (j >= config.ctrl_cols)
                {
                    para_grid.RowDefinitions.Add(new RowDefinition());
                    i++; j = 0;
                }
            }
            #endregion
            #region 菜单指令
            i = 0; j = 0;
            mi_menu_cmd.Header = config.menu_name;
            mi_menu_cmd.Click += (s, e) => { mi_menu_cmd.IsSubmenuOpen = true; };
            foreach (var item in config.menu_cmd)
            {                                                       //本来有一行
                commc.cmds[item.name] = item;
                int rownu = grid_menu_cmd.RowDefinitions.Count - 1; //添加一行
                var v     = CCmd_Button.bt_factory(item.type, item, grid_menu_cmd);
                v.ini(ref i, ref j);
                if (j >= config.menu_cols)
                {
                    grid_menu_cmd.RowDefinitions.Add(new RowDefinition());
                    i++; j = 0;
                }
            }
            #endregion
            _so_tx_cb = new Mingw.DllcallBack(so_tx_cb);             //构造不被回收的委托
            try
            {
                Mingw.so_ini(_so_tx_cb);
            }
            catch
            {
                is_plugin = false;
            }
            dispatcherTimer          = new DispatcherTimer();
            dispatcherTimer.Tick    += new EventHandler(OnTimedEvent);
            dispatcherTimer.Interval = TimeSpan.FromMilliseconds(10);
            dispatcherTimer.Start();
            //配置初始化指令
            foreach (var item in config.ctrl_cmds)
            {
                ctrl_cmd(item);
            }
        }
Ejemplo n.º 2
0
        public void mc_ini()                   //测控界面初始化
        {
            deinit();                          //先去除初始化
            commc.ini(Config.config.prot_cfg); //测控后台初始化
            #region  感参数部分
            chart1 = mainFGrid.Child as Chart;
            chart1.Legends[0].DockedToChartArea = "ChartArea1";
            chart1.Legends[0].BackColor         = System.Drawing.Color.Transparent;
            //从配置中加载参数
            chart1.Series.Clear();
            foreach (var item in commc.dset)
            {
                var ds = item.Value;
                ds.update_cb  = tn => { ds.update_times = 10; };               //数据更新回调函数
                ds.update_dis = tn => { if (ds.update_times > 0)
                                        {
                                            ds.update_times--;
                                        }
                };
                if (ds.is_dis == false)
                {
                    continue;
                }
                CheckBox cb = new CheckBox();
                cb.Content   = ds.name;
                cb.IsChecked = ds.is_cv;
                //cb.Width = 150;
                cb.Background = Brushes.LightCoral;
                cb.Margin     = new Thickness(2, 2, 2, 0);
                Series tmpserial = null;
                if (ds.val.type == DataType.str || ds.val.type == DataType.undef)                 //字符型的,不让选择曲线
                {
                    ds.is_val = false;
                    //cb.IsEnabled = false;
                }
                else                 //曲线型的
                {
                    ds.is_val = true;
                    tmpserial = new Series()
                    {
                        BorderWidth = 2,
                        ChartArea   = "ChartArea1",
                        ChartType   = SeriesChartType.Line,
                        //Color = System.Drawing.Color.Red,
                        Legend = "Legend1",
                        Name   = ds.name,
                    };
                    chart1.Series.Add(tmpserial);
                    series_map[ds.name] = tmpserial;
                }
                checkb_map[ds.name] = cb;
                sp_measure.Children.Add(cb);
                ds.update_cb += (delegate(DataDes dd)                  //数据更新回调函数
                {
                    try
                    {
                        //it.update_times = 10;
                        if (dd.is_val && (bool)cb.IsChecked)               //若显示曲线
                        {
                            if (is_first == 1)                             //首次加入数据点,清除初始化点
                            {
                                clear_Click(null, null);
                                is_first = 0;
                            }
                            double d = dd.val.get_val();
                            if (Math.Abs(d) >= (double)Decimal.MaxValue)
                            {
                                throw new Exception("");
                            }
                            if (x_axis_id != "" && commc.dset.ContainsKey(x_axis_id))                             //若有索引列
                            {
                                if (tmpserial.Points.Count > 0 &&
                                    Math.Abs(tmpserial.Points[tmpserial.Points.Count - 1].XValue - x_tick) < 0.1f)                                     //跟上次一样
                                {
                                    tmpserial.Points[tmpserial.Points.Count - 1].YValues[0] = d;
                                }
                                else
                                {
                                    tmpserial.Points.AddXY(x_tick, d);
                                }
                                if (dd.name == x_axis_id)
                                {
                                    x_tick++;                                                       //若是x轴的索引参数
                                }
                            }
                            else                             //没有索引列,就用时间ms数作为x轴
                            {
                                tmpserial.Points.AddXY(ticks0 - st_ms, d);
                            }
                            if (tmpserial.Points.Count >= Config.config.dis_data_len)
                            {
                                tmpserial.Points.RemoveAt(0);
                            }
                        }
                    }
                    catch { }
                });
                ds.update_dis += (delegate(DataDes dd)           //数据更新回调函数
                {
                    if (dd.update_times > 0)                     //若有数据更新
                    {
                        //it.update_times--;
                        cb.Background = Brushes.LightGreen;
                        cb.Content = dd.name + ":" + dd.val.ToString();
                    }
                    else
                    {
                        cb.Background = Brushes.LightCoral;
                    }
                });
            }
            chart1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = ChartDashStyle.DashDot;

            chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle     = ChartDashStyle.DashDot;
            chart1.ChartAreas[0].AxisY.MajorTickMark.LineDashStyle = ChartDashStyle.DashDot;

            chart1.ChartAreas[0].Axes[0].Maximum = 100;
            chart1.ChartAreas[0].Axes[0].Minimum = 0;
            chart1.ChartAreas[0].Axes[1].Maximum = 30;
            chart1.ChartAreas[0].Axes[1].Minimum = 20;
            //chart1.Series[0].Points.Add(0);
            //chart1.Series[0].Points.Add(0);
            sp_measure.Columns = Config.config.svar_cols;
            if (Config.config.svar_ui_h != 0)             //传感变量区域高度
            {
                row_para_dis.Height = new GridLength(Config.config.svar_ui_h);
            }
            else
            {
                row_para_dis.Height = new GridLength(
                    (sp_measure.Children.Count + sp_measure.Columns - 1) / sp_measure.Columns * 22 + 15);           //行数*22
            }
            //sp_measure.Height = row_para_dis.Height.Value;
            #endregion
            #region 指令ui初始化
            CCmd_para.i_on  = new BitmapImage(new Uri("pack://application:,,,/pic/refresh_on.jpg"));
            CCmd_para.i_off = new BitmapImage(new Uri("pack://application:,,,/pic/refresh_off.jpg"));
            if (Config.config.cmd_ui_w > 0)             //指令区域宽度
            {
                colD_cmd_ui.Width = new GridLength(Config.config.cmd_ui_w);
            }
            if (Config.config.ctrl_cols >= 3)             //若是3列排布的,把默认控制按钮的位置改一下
            {
                //通用控制按钮列数增加
                for (int k = 0; k < Config.config.ctrl_cols - 2; k++)
                {
                    grid_ctrl_bts.ColumnDefinitions.Add(new ColumnDefinition());                //通用控制按钮
                    para_grid.ColumnDefinitions.Add(new ColumnDefinition());                    //配置按钮面板
                }
                //通用控制按钮位置修改
                System.Windows.Controls.Grid.SetRow(cb_datasrc, 0);
                System.Windows.Controls.Grid.SetColumn(cb_datasrc, 0);
                System.Windows.Controls.Grid.SetRow(bt_open_datasrc, 0);
                System.Windows.Controls.Grid.SetColumn(bt_open_datasrc, 1);
                System.Windows.Controls.Grid.SetRow(bt_refresh_uart, 0);
                System.Windows.Controls.Grid.SetColumn(bt_refresh_uart, 2);

                System.Windows.Controls.Grid.SetRow(checkb_rec_data, 1);
                System.Windows.Controls.Grid.SetColumn(checkb_rec_data, 0);
                System.Windows.Controls.Grid.SetRow(cb_fit_screen, 1);
                System.Windows.Controls.Grid.SetColumn(cb_fit_screen, 1);
                System.Windows.Controls.Grid.SetRow(bt_clear, 1);
                System.Windows.Controls.Grid.SetColumn(bt_clear, 2);
                //面板border加长
                System.Windows.Controls.Grid.SetColumnSpan(bd_dft_and_cfg, Config.config.ctrl_cols);
            }
            else             //2列布局,也要从新写一遍
            {
                //通用控制按钮位置修改
                System.Windows.Controls.Grid.SetRow(cb_datasrc, 0);
                System.Windows.Controls.Grid.SetColumn(cb_datasrc, 0);
                System.Windows.Controls.Grid.SetRow(bt_open_datasrc, 0);
                System.Windows.Controls.Grid.SetColumn(bt_open_datasrc, 1);

                System.Windows.Controls.Grid.SetRow(bt_refresh_uart, 1);
                System.Windows.Controls.Grid.SetColumn(bt_refresh_uart, 0);
                System.Windows.Controls.Grid.SetRow(checkb_rec_data, 1);
                System.Windows.Controls.Grid.SetColumn(checkb_rec_data, 1);

                System.Windows.Controls.Grid.SetRow(cb_fit_screen, 2);
                System.Windows.Controls.Grid.SetColumn(cb_fit_screen, 0);
                System.Windows.Controls.Grid.SetRow(bt_clear, 2);
                System.Windows.Controls.Grid.SetColumn(bt_clear, 1);
                //面板border
                System.Windows.Controls.Grid.SetColumnSpan(bd_dft_and_cfg, 2);
            }
            int i = 0, j = 0;                        //i行,j列
            foreach (var item in Config.config.cmds) //遍历配置中的指令,加入到列表中
            {                                        //本来有一行
                commc.cmds[item.name] = item;        //加入指令列表
                var v = CCmd_Button.bt_factory(item.type, item, para_grid);
                v.ini(ref i, ref j);
                if (j >= Config.config.ctrl_cols)                 //自动添加行只在控件本身放不下的情况下做。放下了就需要这里添加行
                {
                    para_grid.RowDefinitions.Add(new RowDefinition());
                    i++; j = 0;
                }
                cmd_ctrl_dict[item.name] = v;                 //加入控件列表
            }
            #endregion
            #region 菜单指令
            i = 0; j = 0;
            mi_menu_cmd.Header = Config.config.menu_name;
            foreach (var item in Config.config.menu_cmd)
            {                                                       //本来有一行
                commc.cmds[item.name] = item;
                int rownu = grid_menu_cmd.RowDefinitions.Count - 1; //添加一行
                var v     = CCmd_Button.bt_factory(item.type, item, grid_menu_cmd);
                v.ini(ref i, ref j);
                if (j >= Config.config.menu_cols)
                {
                    grid_menu_cmd.RowDefinitions.Add(new RowDefinition());
                    i++; j = 0;
                }
            }
            #endregion
        }