private void btnScan_Click(object sender, EventArgs e) { try { if (btnScan.Text == "扫描") { if (comMon == null) { labStatus.Text = "请确定串口是否打开?"; labStatus.ForeColor = Color.Red; return; } if (txtAddr.Text == "") { labStatus.Text = "请输入设置地址号."; labStatus.ForeColor = Color.Red; return; } int wStartAddr = System.Convert.ToInt16(txtStartAddr.Text); int wEndAddr = System.Convert.ToInt16(txtEndAddr.Text); if (wStartAddr >= wEndAddr) { labStatus.Text = "末尾地址需大于等于设置地址."; labStatus.ForeColor = Color.Red; return; } curAddr = System.Convert.ToInt16(txtStartAddr.Text); gridMon.Rows.Clear(); rowNum = 0; cancel = false; scanHandler scan = new scanHandler(OnScan); scan.BeginInvoke(null, null); btnScan.Text = "停止"; } else { cancel = true; btnScan.Text = "扫描"; } } catch (Exception) { throw; } finally { } }
private void btnScan_Click(object sender, EventArgs e) { try { if (btnScan.Text == "扫描") { if (!checkSystem()) { return; } btnScan.Text = "停止"; curAddr = System.Convert.ToInt16(txtStartAddr.Text); ERSView.Rows.Clear(); rowNum = 0; cancel = false; scanHandler scan = new scanHandler(OnScan); scan.BeginInvoke(null, null); } else { cancel = true; btnScan.Text = "扫描"; } } catch (Exception) { throw; } }