//_________________________________________________________________________ private void BDisconn_Click(object sender, EventArgs e) { if (CP == null) { CP = new CComPort(this); if (CP.PortCreate()) { OpeningPort(); } } else { if (CP.IsOpen) { CP.PortClose(); BOpenCom.Text = "Открыть"; BOpenCom.ImageIndex = 1; } else { OpeningPort(); } } }
//_________________________________________________________________________ private void BReadCOM_Click(object sender, EventArgs e) { try { if (CP == null) { CP = new CComPort(this); if (CP.PortCreate() == false) { CP = null; return; } OpeningPort(); } //CP?.PortClose (); //CP = new CComPort (this); //if (CP.CreatePort () == false) //{ // MessageBox.Show ("Порт [" + CP.SP?.PortName + "] не открыт"); // CP = null; // return; //} byte[] btaTX; bool bRet = false; int iCountRequest = 0; if (ChBModeRequest.Checked) { bRet = SendTopRequest(out btaTX, ref iCountRequest); } else { bRet = SendTestRequest(out btaTX); } if (bRet) { CP.SendComm(btaTX, 0, btaTX.Length); if (Properties.Settings.Default.asCommand.Contains(TBCommand.Text) == false) { Properties.Settings.Default.asCommand = TBCommand.Text; } } else { TBCommand.AppendText("Неверная команда " + TBCommand.Lines[iCountRequest]); } if (bSavePropertyes) { bSavePropertyes = false; Properties.Settings.Default.Save(); } } catch (Exception exc) { MessageBox.Show(exc.Message + Environment.NewLine + exc.StackTrace); if (CP != null && CP.PortOpen()) { CP.PortClose(); } } }