예제 #1
0
 private bool PortCtrl(bool ctrl)
 {
     if (true == ctrl)
     {
         if (scom.IsOpen == false)
         {
             try
             {
                 scom.Config(combPortNum.Text, Convert.ToInt32(combPortBaud.Text), combPortChk.Text);
                 scom.Open();
             }
             catch (Exception ex)
             {
                 MessageBox.Show("打开通信端口失败" + "," + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return(false);
             }
         }
     }
     else
     {
         try
         {
             scom.Close();
         }
         catch (System.Exception ex)
         {
             MessageBox.Show("关闭通信端口失败" + "," + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return(false);
         }
     }
     return(true);
 }