Beispiel #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (button1.Text == "关闭")
     {
         try
         {
             HandleRst rst = comm.OnStop();
             comm.Dispose();
             comm = null;
         }
         catch (Exception)
         {
             throw;
         }
         button1.Text = "打开";
     }
     else
     {
         string portName = cbxPortName.SelectedItem.ToString();
         if (string.IsNullOrEmpty(portName))
         {
             MessageBox.Show("请选择一个串口!!!");
             return;
         }
         int BaudRate;
         if (!int.TryParse(cbxBaudList.Text, out BaudRate))
         {
             MessageBox.Show("请选择一个波特率!!!");
             return;
         }
         comm = new SerialImpl(portName, BaudRate);
         this.DialogResult = DialogResult.OK;
     }
 }
Beispiel #2
0
 private void btnConn_Click(object sender, EventArgs e)
 {
     if (this.btnConn.Text == "断开")
     {
         try
         {
             HandleRst rst = conn.OnStop();
             conn.Dispose();
             conn = null;
         }
         catch (Exception)
         {
             throw;
         }
         btnConn.Text = "连接";
     }
     else
     {
         string strIP = RemoteIP.Text.Trim();
         try
         {
             IPAddress ip = IPAddress.Parse(strIP);
         }
         catch (Exception)
         {
             MessageBox.Show("IP格式有错误,请重新输入!");
             return;
         }
         int port = 0;
         try
         {
             bool bflag = int.TryParse(RemotePort.Text.Trim(), out port);
             if (!bflag)
             {
                 MessageBox.Show("端口输入有错误,请重新输入!");
                 return;
             }
         }
         catch (Exception)
         {
             MessageBox.Show("端口输入有错误,请重新输入!");
             return;
         }
         conn = new TcpCliImpl(strIP, port);
         this.DialogResult = DialogResult.OK;
     }
 }