예제 #1
0
        private void Connect()
        {
            this.portname     = txtPortName.Text;
            this.mySerialPort = new MySerialPort(this.portname, getRatio(), this.receivePath);
            this.mySerialPort.messageIsHere   += new MySerialPort.HandlerReceiveMessage(this.messageReceived);
            this.mySerialPort.tramaHire       += new MySerialPort.HandlerNotifyProgress(this.onTramaHire);
            this.mySerialPort.notifyName      += new MySerialPort.HandlerNotifyProgress(this.onFileNameAddToCahtPanel);
            this.mySerialPort.sendingProgress += new MySerialPort.HandlerNotifyProgress(this.upadateProgressOnChatPanel);

            try {
                if (mySerialPort.Connect())
                {
                    this.lblState.Text      = "OnLine " + portname;
                    this.lblState.ForeColor = Color.Green;
                    this.btnConnect.Text    = "Disconnect";
                    this.myInputBox.ComponentesState(true);
                    this.txtPortName.Enabled     = false;
                    this.txtRatioBaudios.Enabled = false;
                    this.txtSetting.Enabled      = false;
                }
                else
                {
                    this.lblState.Text      = "OfLine";
                    this.lblState.ForeColor = Color.Red;
                    this.btnConnect.Text    = "Reconnect";
                    MessageBox.Show(this, "Connect error");
                }
            }catch (Exception err)
            {
                this.lblState.Text      = err.Message;
                this.lblState.ForeColor = Color.Red;
            }
        }