Пример #1
0
 private void ConnectCb_Click(object sender, EventArgs e)
 {
     if (!ConnectCb.Checked)
     {
         if (_comPortManager.IsConnected)
         {
             Deinit();
         }
         ConnectCb.Text = "Connect";
         DebugLog($"Disconnected from COM port\r\n");
         //ConnectCb.Checked = false;
     }
     else
     {
         if (!_comPortManager.IsConnected)
         {
             ComPortSelectionItem item = (ComPortSelectionItem)ComPortsCb.SelectedItem;
             ConnectCb.Checked = false;
             if (item != null)
             {
                 if (_comPortManager.OpenComPort(item.ComPort))
                 {
                     ConnectCb.Text    = "Disconnect";
                     ConnectCb.Checked = true;
                     Init();
                     DebugLog($"Connected to COM port {item.ComPort}\r\n");
                 }
             }
         }
     }
 }
Пример #2
0
        /*
         * private void Test()
         * {
         *      string fullName = Path.Combine(Constants.LOG_PATH, "test.log");
         *      string[] lines = File.ReadAllLines(fullName);
         *
         *      Init();
         *      foreach(string line in lines)
         *      {
         *              DoLine(line);
         *      }
         * }
         */

        private void ComPortsCb_MouseClick(object sender, MouseEventArgs e)
        {
            // save selection
            ComPortSelectionItem saveItem = (ComPortSelectionItem)ComPortsCb.SelectedItem;

            // refresh com port list
            List <ComPortSelectionItem> newComPortList = _comPortManager.GetPorts();

            ComPortsCb.DataSource = newComPortList;

            // restore selection
            if (saveItem != null)
            {
                foreach (ComPortSelectionItem selItem in newComPortList)
                {
                    if (selItem.ComNumber == saveItem.ComNumber)
                    {
                        ComPortsCb.SelectedItem = saveItem;
                        ComPortsCb.Text         = saveItem.ComPort;
                        break;
                    }
                }
            }
        }