示例#1
0
 public static Serial_Setup Getsingle()
 {
     if (serialsingle == null)
     {
         serialsingle = new Serial_Setup();
     }
     return(serialsingle);
 }
示例#2
0
        private void Serial_Set_Click(object sender, EventArgs e)
        {
            Serial_Setup serialsetup = Serial_Setup.Getsingle();
            DialogResult result      = serialsetup.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                flag = true;
                if (serialsetup.Com_Baudrate.SelectedIndex != 0)
                {
                    serialpara.comBaudrate = Convert.ToInt32(serialsetup.Com_Baudrate.Text);
                }
                else
                {
                    Custom_baudrateForm custom = new Custom_baudrateForm();
                    result = custom.ShowDialog();
                    {
                        if (result != System.Windows.Forms.DialogResult.OK || serialpara.comBaudrate == 0)
                        {
                            MessageBox.Show("Please int a number in Baudrate", "TGUS", MessageBoxButtons.OK);
                        }
                    }
                }
                serialpara.comDatabits = Convert.ToInt32(serialsetup.Com_Databits.Text);
                switch (serialsetup.Com_Stopbits.SelectedIndex)
                {
                case 0:
                    serialpara.comStopbits = System.IO.Ports.StopBits.One;
                    break;

                case 1:
                    serialpara.comStopbits = System.IO.Ports.StopBits.OnePointFive;
                    break;

                case 2:
                    serialpara.comStopbits = System.IO.Ports.StopBits.Two;
                    break;
                }
                switch (serialsetup.Com_Parity.SelectedIndex)
                {
                case 0:
                    serialpara.comParity = System.IO.Ports.Parity.None;
                    break;

                case 1:
                    serialpara.comParity = System.IO.Ports.Parity.Odd;
                    break;

                case 2:
                    serialpara.comParity = System.IO.Ports.Parity.Even;
                    break;

                case 3:
                    serialpara.comParity = System.IO.Ports.Parity.Mark;
                    break;

                case 4:
                    serialpara.comParity = System.IO.Ports.Parity.Space;
                    break;
                }
                serialpara.Timeout = Convert.ToInt32(serialsetup.Time_OutTextBox.Text);
            }
        }