Пример #1
0
        private void ok_Click(object sender, EventArgs e)
        {
            if (!isP)
            {
                Notify notify = new Notify("资源正在准备,请稍后...");
                notify.Show();
                return;
            }
            this.timer1.Stop();
            if (!isOpen)
            {
               // if (!comm.IsOpen)
                if(true)
                {
                    //关闭时点击,则设置好端口,波特率后打开
                    comm.PortName = comboPortName.Text;
                    comm.BaudRate = int.Parse(comboBaudrate.Text);
                    comm.DataBits = int.Parse(comboBoxDataBit.Text);
                    switch (comboBoxStopBit.SelectedIndex)
                    {

                        case -1:
                            comm.StopBits = StopBits.One;
                            break;
                        case 0:
                            comm.StopBits = StopBits.One;
                            break;
                        case 1:
                            comm.StopBits = StopBits.Two;
                            break;
                        // comm.StopBits = StopBits.None;
                    }

                    //把字符串转换为eunm枚举类型。
                    comm.Parity = (Parity)Enum.Parse(typeof(Parity), comboBoxParity.SelectedItem.ToString());
                    try
                    {
                        comm.Open(); //打开串口
                        mainHome.startCount();
                    }
                    catch (Exception ex)
                    {
                        //捕获到异常信息,创建一个新的comm对象,之前的不能用了。
                        //comm = new SerialPort();
                        //现实异常信息给客户。
                        MessageBox.Show(ex.Message);
                        return;
                    }
                    isOpen = true;
                }
            }
            //mainHome = new MainHome(comm);
            //Origination or = new Origination(mainHome);
            Thread.Sleep(1);
            if(pOk)
            {
                or.Show();
                this.Hide();
            }
            else
            {
                Notify notify = new Notify("资源正在准备,请稍后...");
                notify.Show();
                return;
            }
            this.timer1.Dispose();
            //串口线程启动
            mainHome.StartSerialPort();

            this.comboBaudrate.Dispose();
            this.comboBoxDataBit.Dispose();
            this.comboBoxStopBit.Dispose();
            this.comboPortName.Dispose();
            this.label1.Dispose();
            this.label2.Dispose();
            this.label3.Dispose();
            this.label4.Dispose();
            this.label5.Dispose();
            //this.label6.Dispose();
            this.label8.Dispose();
            //this.Dispose();
        }
Пример #2
0
        private void ok_Click(object sender, EventArgs e)
        {
            if (!isP)
            {
                Notify notify = new Notify("资源正在准备,请稍后...");
                notify.Show();
                return;
            }
            this.timer1.Stop();
            if (!isOpen)
            {
                // if (!comm.IsOpen)
                if (true)
                {
                    //关闭时点击,则设置好端口,波特率后打开
                    comm.PortName = comboPortName.Text;
                    comm.BaudRate = int.Parse(comboBaudrate.Text);
                    comm.DataBits = int.Parse(comboBoxDataBit.Text);
                    switch (comboBoxStopBit.SelectedIndex)
                    {
                    case -1:
                        comm.StopBits = StopBits.One;
                        break;

                    case 0:
                        comm.StopBits = StopBits.One;
                        break;

                    case 1:
                        comm.StopBits = StopBits.Two;
                        break;
                        // comm.StopBits = StopBits.None;
                    }

                    //把字符串转换为eunm枚举类型。
                    comm.Parity = (Parity)Enum.Parse(typeof(Parity), comboBoxParity.SelectedItem.ToString());
                    try
                    {
                        comm.Open(); //打开串口
                        mainHome.startCount();
                    }
                    catch (Exception ex)
                    {
                        //捕获到异常信息,创建一个新的comm对象,之前的不能用了。
                        //comm = new SerialPort();
                        //现实异常信息给客户。
                        MessageBox.Show(ex.Message);
                        return;
                    }
                    isOpen = true;
                }
            }
            //mainHome = new MainHome(comm);
            //Origination or = new Origination(mainHome);
            Thread.Sleep(1);
            if (pOk)
            {
                or.Show();
                this.Hide();
            }
            else
            {
                Notify notify = new Notify("资源正在准备,请稍后...");
                notify.Show();
                return;
            }
            this.timer1.Dispose();
            //串口线程启动
            mainHome.StartSerialPort();

            this.comboBaudrate.Dispose();
            this.comboBoxDataBit.Dispose();
            this.comboBoxStopBit.Dispose();
            this.comboPortName.Dispose();
            this.label1.Dispose();
            this.label2.Dispose();
            this.label3.Dispose();
            this.label4.Dispose();
            this.label5.Dispose();
            //this.label6.Dispose();
            this.label8.Dispose();
            //this.Dispose();
        }