private void btnConnect_Click(object sender, EventArgs e) { if (cbComList.SelectedItem == null) return; if (serialService != null) serialService.Close(); serialService = new SerialService(cbComList.SelectedItem.ToString()); if (!serialService.Open()) { MessageBox.Show("Cannot open COM port!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SetDisconnectedState(); return; } CmdVersion cmdVer = new CmdVersion(); if (serialService.SendCommand(cmdVer)) { MessageBox.Show(string.Format("Connected with device {0}!", cmdVer.DeviceVersion), "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Device did not answer correctly. Maybe this is not SmartPHT?", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Warning); } SetConnectedState(); }
private void btnCloseConn_Click(object sender, EventArgs e) { if (serialService != null) serialService.Close(); serialService = null; }