Пример #1
0
 private void OpenCom()
 {
     try
     {
         if (!cbbBaud.Items.Contains(cbbBaud.Text))
         {
             cbbBaud.Items.Add(cbbBaud.Text);
         }
         cbbBaud.DropDownStyle = ComboBoxStyle.DropDownList;
         com = new All.Communicate.Com();
         com.CommunicateErrorRaise += com_CommunicateErrorRaise;
         Dictionary <string, string> buff = new Dictionary <string, string>();
         com.Init(buff);
         com.Open();
         if (com.IsOpen)
         {
             ucCommunite1.SetCommunicate(com);
             btnOpen.Text            = "关闭";
             btnOpen.BackgroundImage = AllTools.Properties.Resources.Close;
         }
         else
         {
             CloseCom();
         }
     }
     catch (Exception e)
     {
         using (All.Window.MessageWindow mw = new All.Window.MessageWindow(e.Message, "错误", All.Window.MessageWindow.EButton.OK, All.Window.MessageWindow.EIcon.Error))
         {
             mw.ShowDialog();
         }
     }
 }
Пример #2
0
 private void CloseCom()
 {
     try
     {
         com.CommunicateErrorRaise -= com_CommunicateErrorRaise;
         if (com != null)
         {
             com.Close();
             com = null;
         }
         cbbBaud.DropDownStyle   = ComboBoxStyle.DropDown;
         btnOpen.Text            = "打开";
         btnOpen.BackgroundImage = AllTools.Properties.Resources.Open;
     }
     catch { }
 }