Пример #1
0
        public Port()
        {
            InitializeComponent();
            CmbPortName1.Items.AddRange(System.IO.Ports.SerialPort.GetPortNames());
            CmbPortName2.Items.AddRange(System.IO.Ports.SerialPort.GetPortNames());
            //载入生产模式
            switch (Main.mode)
            {
            case Main.Mode.旧机器API2:
                旧机器API2ToolStripMenuItem.Checked = true;
                GrpPort1.Enabled = true;
                break;

            case Main.Mode.无串口:
                无串口ToolStripMenuItem.Checked = true;
                GrpPort1.Enabled             = false;
                GrpPort2.Enabled             = false;
                break;
            }
            #region load注册表
            if (Regedit.isRegeditKeyExit("Port"))
            {
                RegistryKey myreg     = Registry.LocalMachine.OpenSubKey(@"software\NTRS");
                String[]    valueList = (String[])(myreg.GetValue("Port"));
                if (valueList.Length == 5 || valueList.Length == 10)
                {
                    CmbPortName1.Text = valueList[0];
                    CmbBaudRate1.Text = valueList[1];
                    CmbParity1.Text   = valueList[2];
                    CmbDataBits1.Text = valueList[3];
                    CmbStopBits1.Text = valueList[4];
                    if (valueList.Length == 10)
                    {
                        CmbPortName2.Text = valueList[5];
                        CmbBaudRate2.Text = valueList[6];
                        CmbParity2.Text   = valueList[7];
                        CmbDataBits2.Text = valueList[8];
                        CmbStopBits2.Text = valueList[9];
                    }
                }
            }


            if (Regedit.isRegeditKeyExit("Identifier"))
            {
                RegistryKey myreg = Registry.LocalMachine.OpenSubKey(@"software\NTRS");
                identifier = (String)(myreg.GetValue("Identifier"));

                switch (identifier)
                {
                case "\r":
                    TxtIdentifier.Text = "[CR]";
                    break;

                case "\n":
                    TxtIdentifier.Text = "[LF]";
                    break;

                default:
                    TxtIdentifier.Text = identifier;
                    break;
                }
            }
            #endregion
        }
Пример #2
0
        public Trajectory()
        {
            InitializeComponent();

            #region 布局
            TlpLayout.RowCount    = NTRSbyDB.Layout.row;
            TlpLayout.ColumnCount = NTRSbyDB.Layout.col;

            for (int i = 0; i < NTRSbyDB.Layout.row; i++)
            {
                TlpLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
            }
            for (int i = 0; i < NTRSbyDB.Layout.col; i++)
            {
                TlpLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
            }

            for (int i = 0; i < NTRSbyDB.Layout.row; i++)
            {
                for (int j = 0; j < NTRSbyDB.Layout.col; j++)
                {
                    Label label = new Label();
                    label.Dock      = DockStyle.Fill;
                    label.BackColor = Color.Red;
                    label.Text      = "\r\n\r\n\r\n(" + (j + 1).ToString() + "," + (i + 1).ToString() + ")";
                    label.Click    += new EventHandler(clickMark);
                    TlpLayout.Controls.Add(label, j, i);
                    //下面这句要是在行和列不够的情况下,会建到100行1000列
                    //tableLayoutPanel1.Controls.Add(label1, 100, 1000);
                }
            }

            void clickMark(object sender, EventArgs e)
            {
                Label label = (Label)sender;

                label.Text      = label.Text.Insert(0, (++sequence).ToString());
                label.BackColor = Color.Lime;
                label.Enabled   = false;
                sequenceList.Add((TlpLayout.GetColumn(label) + 1).ToString()
                                 + ","
                                 + (TlpLayout.GetRow(label) + 1).ToString());
            }

            #endregion
            //存在key且通过验证就显示次序顺序
            #region load注册表
            if (Regedit.isRegeditKeyExit("Trajectory"))
            {
                if (!Regedit.verifyTrajectory())
                {
                    return;
                }

                RegistryKey myreg        = Registry.LocalMachine.OpenSubKey(@"software\NTRS");
                String[]    sequenceList = (String[])(myreg.GetValue("Trajectory"));
                //验证:读取的字符串能匹配上布局的定义坐标(1,1\1,2等)
                foreach (string str in sequenceList)
                {
                    //遍历控件对比
                    for (int i = 0; i < TlpLayout.Controls.Count; i++)
                    {
                        if (TlpLayout.Controls[i].Text.Contains(str))
                        {
                            TlpLayout.Controls[i].BackColor = Color.Lime;
                            TlpLayout.Controls[i].Enabled   = false;
                            TlpLayout.Controls[i].Text      = TlpLayout.Controls[i].Text.Insert(0, (++sequence).ToString());
                            break;
                        }
                        #region Regedit.verifyTrajectory()覆盖该过程
                        ////全部验证成功才显示次序(只要有一个验证不了,全部取消)
                        ////Regedit.verifyTrajectory()一定要元素相等且相同才可进这里,所以不需要下面这
                        //if (i == tableLayoutPanel1.Controls.Count-1)
                        //{
                        //    cancel_btn_Click(new object (), new EventArgs ());
                        //    return;
                        //}
                        #endregion
                    }
                    #region 索引(比较复杂,用遍历方法实现)
                    ////tableLayoutPanel1.Controls.Add(label, j, i);
                    ////string test=tableLayoutPanel1.Controls[1].Text;
                    ////string a=tableLayoutPanel1.Controls[0,1].Text;
                    //int row=int.Parse(str.Split(',')[0]);
                    //int col = int.Parse(str.Split(',')[1]);
                    ////2,2
                    //int r=row % NTRSjudge.Layout.row;
                    //int c = col % NTRSjudge.Layout.col;
                    #endregion
                }
            }
            #endregion
        }