private void btnCalcFCS_Click(object sender, EventArgs e) { tbFCS.Text = ""; Functions.Delay(50); string frm = ""; frm = (ckbAPDUDiv.Checked) ? (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) : (tbLen.Text + tbCtl.Text + tbAF.Text + tbSA.Text + tbCA.Text + tbHCS.Text + tbAPDU.Text); frm = frm.Replace(" ", "").Replace("\n", "").Replace("\r", ""); 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 //|| tbAPDU.Text.Replace(" ", "").Replace("\n", "").Replace("\r", "").Length < 2 || frm.Length % 2 == 1) { MessageBox.Show("请输入正确帧!"); } else { ushort fcs = Protocol698.pppfcs16(frm); tbFCS.Text = (fcs & 0x00ff).ToString("X2") + " " + ((fcs >> 8) & 0x00ff).ToString("X2"); } tbFCS.Update(); }
private void btnCalcHCS_Click(object sender, EventArgs e) { tbHCS.Text = ""; Functions.Delay(50); string frm = tbLen.Text + tbCtl.Text + tbAF.Text + tbSA.Text + tbCA.Text; frm = frm.Replace(" ", "").Replace("\n", "").Replace("\r", ""); 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 || frm.Length % 2 == 1) { MessageBox.Show("请输入正确帧!"); } else { ushort hcs = Protocol698.pppfcs16(frm); tbHCS.Text = (hcs & 0x00ff).ToString("X2") + " " + ((hcs >> 8) & 0x00ff).ToString("X2"); } }
private string GetCs(string str) { ushort hcs = Protocol698.pppfcs16(str); return((hcs & 0x00ff).ToString("X2") + ((hcs >> 8) & 0x00ff).ToString("X2")); }