Beispiel #1
0
        private void WriteClick()
        {
            s                     = ConState.write;
            dataerrer             = true;
            issessce              = false;
            Common.Common.massage = "";
            //writeP();
            if (PortCommunication.ComName == null)
            {
                mondelName.Text = "Select Port ...";
                GetComList(); //获取端口
                if (PortCommunication.ComName == null)
                {
                    MessageBox.Show("Please Select Port ...");
                    foreach (Control item in this.Controls)
                    {
                        item.Enabled = true;
                    }
                    return;
                }
            }
            //lg = new Loading();

            //lg.Location = new Point(this.Width / 2 - lg.Width / 2, this.Height / 2 - lg.Height / 2);
            //lg.TopLevel = false;
            //lg.Parent = this;
            try
            {
                PortCommunication.NewSerialPort();

                PortCommunication.openPort();
            }
            catch (Exception)
            {
                MessageBox.Show("The port failed to open, please check the port!");
                foreach (Control item in this.Controls)
                {
                    item.Enabled = true;
                }
                return;
            }

            conn = new Thread(br3.writeMessage);



            conn.IsBackground = true;
            PortCommunication.timerSend.Interval = PortCommunication.timeout;
            PortCommunication.timerSend.Enabled  = true;
            PortCommunication.timerSend.Start();
            //timer1.Start();
            foreach (Control item in this.Controls)
            {
                item.Enabled = false;
            }
            conn.Start();
            //lg.BringToFront();
            //lg.Show();
        }
Beispiel #2
0
        private void ReadClick()
        {
            s                     = ConState.read;
            dataerrer             = true;
            issessce              = false;
            Common.Common.massage = "";
            if (PortCommunication.ComName == null)
            {
                mondelName.Text = "Select Port ...";
                GetComList(); //获取端口
                if (PortCommunication.ComName == null)
                {
                    MsgBox.Show("Please Select Port ...");
                    SetEnable(true);
                    return;
                }
            }

            //lg = new Loading();
            //lg.Location = new Point(this.Width / 2 - lg.Width / 2,  this.Height / 2 - lg.Height / 2);
            //lg.TopLevel = false;
            //try
            //{
            //    lg.Parent = this;
            //}
            //catch (Exception)
            //{

            //    ;
            //}

            try
            {
                PortCommunication.NewSerialPort();

                PortCommunication.openPort();
            }
            catch (Exception)
            {
                MsgBox.Show("The port failed to open, please check the port!");
                SetEnable(true);
                return;
            }

            conn = new Thread(br3.readMessage);


            conn.IsBackground = true;
            //timerSend.Interval = timeout;

            PortCommunication.timerSend.Interval = PortCommunication.timeout;
            PortCommunication.timerSend.Enabled  = true;
            PortCommunication.timerSend.Start();

            //timerSend.Start();
            //timer1.Start();
            SetEnable(false);
            conn.Start();
        }