Beispiel #1
0
        //16进制显示
        private void modecheck_CheckedChanged(object sender, EventArgs e)
        {
            string str;

            if (modecheck.Checked)
            {
                str = CRCHelper.ConvertCharToAscii(sourcebox.Text);
                sourcebox.Clear();
                sourcebox.Text = str;
                str            = "";
                str            = CRCHelper.ConvertCharToAscii(crctext.Text);
                str            = str.PadLeft(4, '0');
                crctext.Clear();
                crctext.Text = str;
                str          = "";
            }
            else
            {
                str = CRCHelper.ConvertAsciiToChar(sourcebox.Text);
                sourcebox.Clear();
                sourcebox.Text = str;
                str            = "";
                str            = CRCHelper.ConvertAsciiToChar(crctext.Text);
                str            = str.PadLeft(2, '0');
                crctext.Clear();
                crctext.Text = str;
                str          = "";
            }
            databox.Text = sourcebox.Text + crctext.Text;
        }
Beispiel #2
0
        //计算CRC
        private void crcbtn_Click(object sender, EventArgs e)
        {
            string str;
            char   ls;

            crctext.Text = string.Empty;
            if (modecheck.Checked)
            {
                sourcebox.Text.Replace(" ", "");
                str = CRCHelper.ConvertAsciiToChar(sourcebox.Text);
                if (str == null)
                {
                    return;
                }
                ushort crcnum = CRCHelper.CRC16(str);
                str          = crcnum.ToString("X", NumberFormatInfo.InvariantInfo);
                str          = str.PadLeft(4, '0');
                crctext.Text = str;
                databox.Clear();
                databox.Text = sourcebox.Text + crctext.Text;
            }
            else
            {
                ushort crcnum = CRCHelper.CRC16(sourcebox.Text);

                ls            = (char)((crcnum & 0xFF00) >> 8);
                crctext.Text += ls.ToString();
                ls            = (char)(crcnum & 0xFF);
                crctext.Text += ls.ToString();
                databox.Clear();
                databox.Text = sourcebox.Text + crctext.Text;
            }
        }