Пример #1
0
 //_________________________________________________________________________
 private void ClientClose()
 {
     if (Client != null)
     {
         Client.Close();
         Client = null;
     }
 }
Пример #2
0
 private void BConnect2_Click(object sender, EventArgs e)
 {
     try
     {
         if (bConnClient == false)
         {
             if (Client == null)
             {
                 Client = new CComPortClient(CBComPort.Text, int.Parse(CBBaud.Text), (Parity)Enum.Parse(typeof(Parity), CBParity.Text),
                                             int.Parse(CBDataBit.Text), (StopBits)Enum.Parse(typeof(StopBits), CBStopBits.Text));
                 Client.Log += Inv_OutMess;
             }
             //if (Client == null)						return;
             // Соединение с портом COM
             ThreadPool.QueueUserWorkItem((object oInfo) =>
             {
                 string asComPort = (string)oInfo;
                 Inv_OutMess($"Подключение к {asComPort} ...");
                 bConnClient = Client.Connect();
                 if (bConnClient)
                 {
                     SetTextB(BConnect2, "Разъединить");
                     Inv_OutMess($"Подкл. {asComPort}");
                     //if (bAddPassiveIP)
                     //{
                     //	Properties.Settings.Default.asIPpassiveList = string.Join (";", Properties.Settings.Default.asIPpassiveList, CBComPort.Text);
                     //}
                 }
                 else
                 {
                     Inv_OutMess($"Соединение с {asComPort} не установлено");
                     Client.Close();
                     Client = null;
                 }
             }
                                          , CBComPort.Text);
         }
         else
         {
             ClientClose();
             BConnect2.Text = "Соединить";
             Inv_OutMess($"Откл. {CBComPort.Text}");
             bConnClient = false;
         }
     }
     catch (Exception exc)
     {
         Inv_OutMess($"{CBComPort.Text}: {exc.Message}{Environment.NewLine}{exc.StackTrace}");
     }
 }