private void btn698send_Click(object sender, EventArgs e) { btnClrData_Click(sender, e); if (ckbClearBefore.Enabled && ckbClearBefore.Checked) { tb698Explain.Clear(); } if (ckbAutoCalcLen.Checked) { btnCalcLen_Click(sender, e); } if (ckbAutoCalcChk.Checked) { btnCalcHCS_Click(sender, e); btnCalcFCS_Click(sender, e); } string txString = ""; txString = (ckbAPDUDiv.Checked) ? (tb68.Text + tbLen.Text + tbCtl.Text + tbAF.Text + tbSA.Text + tbCA.Text + tbHCS.Text + tbAPDU_1.Text + tbAPDU_2.Text + tbAPDU_3.Text + tbAPDU_4.Text + tbAPDU_5.Text + tbAPDU_6.Text + tbFCS.Text + tb16.Text) : (tb68.Text + tbLen.Text + tbCtl.Text + tbAF.Text + tbSA.Text + tbCA.Text + tbHCS.Text + tbAPDU.Text + tbFCS.Text + tb16.Text); txString = txString.Replace(" ", "").Replace("\r", "").Replace("\n", ""); if (tbLen.Text.Replace(" ", "").Length != 4 || tbCtl.Text.Replace(" ", "").Length != 2 || tbAF.Text.Replace(" ", "").Length != 2 || tbSA.Text.Replace(" ", "").Length < 2 || tbCA.Text.Replace(" ", "").Length != 2 || tbHCS.Text.Replace(" ", "").Length != 4 || tbFCS.Text.Replace(" ", "").Length != 4 //|| tbAPDU.Text.Replace(" ", "").Replace("\r", "").Replace("\n", "").Length < 2 || txString.Length % 2 == 1) { MessageBox.Show("请输入正确帧!"); return; } Protocol698 p698 = new Protocol698(); string res = p698.SendAndRecv(txString); if (res != null && res.Length > 0) { string[] frm = new string[res.Length / 2]; for (int i = 0; i < res.Length / 2; i++) { frm[i] = res.Substring(i * 2, 2); } int frmLen = Convert.ToInt16(frm[2] + frm[1], 16) + 2; if (frmLen != frm.Length) { return; } OldVerDisp698(frm);//旧版报文接收 if (!ckbOldVerDisp.Checked) { NewVerDisp698(res);//新版报文接收 } } }
private void Comm698Test() { int oadCnt = Oads.Length / 8; string[] oad = new string[oadCnt]; for (int i = 0; i < oadCnt; i++) { oad[i] = Oads.Substring(i * 8, 8); } int cnt = int.Parse(txtCnt.Text); if (cnt == 0) { cnt = 1000000; } Protocol698 p698 = new Protocol698(); for (int i = 0; i < cnt; i++) { string txString = string.Empty; txString = "681700" + "43" + (Addr.Length / 2 - 1).ToString("x2") + Addr.ReverseStr() + "10"; txString += GetCs(txString.Substring(2)); txString += "050101"; Random ro = new Random(); int rand = ro.Next(oadCnt); txString += oad[rand]; txString += "00"; txString += GetCs(txString.Substring(2)); txString += "16"; string res = string.Empty; SendCnt++; string ret = p698.SendAndRecv(txString); if (ret != null && ret.Length > 0) { if (res.Length != 0) { SuccessCnt++; } } double rate = SuccessCnt / SendCnt * 100; txtRate.Text = SuccessCnt + "/" + SendCnt + "*100% = " + rate.ToString() + "%"; } btnTest.Text = "开始测试"; if (TestThread.IsAlive) //判断SetTimeEventTestThread是否存在,不能撤消一个不存在的线程,否则会引发异常 { TestThread.Abort(); //撤消SetTimeEventTestThread } }