예제 #1
0
        private void cbDataCheckType_SelectedIndexChanged(object sender, EventArgs e)
        {
            dataWidth = 8;

            if (_DataBytes == null)
            {
                return;
            }

            gbCRCParam.Enabled = false;

            int index = cbDataCheckType.SelectedIndex;

            if (index == 0)
            {
                dataWidth = 16;
            }
            else if (index == 1)
            {
                dataWidth = 8;
            }
            else if (index == 2)
            {
                dataWidth = 8;
            }
            else
            {
                gbCRCParam.Enabled = true;
                CRCType crcType = (CRCType)(index - 3);
                CRCInfo crcInfo = DataCheck.GetCRCInfo(crcType);

                chkRefIn.Checked  = crcInfo.RefIn;
                chkRefOut.Checked = crcInfo.RefOut;
                chkXorOut.Checked = crcInfo.XorOut == 0 ? false : true;

                if (crcType >= CRCType.CRC16_IBM && crcType <= CRCType.CRC16_DNP)
                {
                    txtPoly.Text = string.Format("{0:X4}", crcInfo.Poly);
                    txtInit.Text = string.Format("{0:X4}", crcInfo.Init);

                    dataWidth = 16;
                }
                else if (crcType >= CRCType.CRC32 && crcType <= CRCType.CRC32_MPEG2)
                {
                    txtPoly.Text = string.Format("{0:X8}", crcInfo.Poly);
                    txtInit.Text = string.Format("{0:X8}", crcInfo.Init);

                    dataWidth = 32;
                }
            }


            CalCheckData();
        }
예제 #2
0
        private void CalCheckData()
        {
            try
            {
                UInt32 checkResult = 0;


                if (_DataBytes == null)
                {
                    return;
                }

                gbCRCParam.Enabled = false;

                int index = cbDataCheckType.SelectedIndex;
                if (index == -1)
                {
                    return;
                }
                if (index == 0)
                {
                    checkResult = Convert.ToUInt16(DataCheck.GetCheckSum(_DataBytes) & 0xFFFF);
                    dataWidth   = 16;
                }
                else if (index == 1)
                {
                    checkResult = Convert.ToByte(DataCheck.GetCheckSum(_DataBytes) & 0xFF);
                    dataWidth   = 8;
                }
                else if (index == 2)
                {
                    checkResult = DataCheck.GetXor(_DataBytes);
                    dataWidth   = 8;
                }
                else
                {
                    gbCRCParam.Enabled = true;

                    CRCType crcType = (CRCType)(index - 3);


                    CRCInfo crcInfo = DataCheck.GetCRCInfo(crcType);
                    crcInfo.Poly   = Convert.ToUInt32(txtPoly.Text, 16);
                    crcInfo.Init   = Convert.ToUInt32(txtInit.Text, 16);
                    crcInfo.RefIn  = chkRefIn.Checked;
                    crcInfo.RefOut = chkRefOut.Checked;
                    crcInfo.XorOut = chkXorOut.Checked ? 0xFFFFFFFF : 0x00000000;



                    if (crcType >= CRCType.CRC16_IBM && crcType <= CRCType.CRC16_DNP)
                    {
                        checkResult = DataCheck.GetCRC16(crcInfo, _DataBytes);
                        dataWidth   = 16;
                    }
                    else if (crcType >= CRCType.CRC32 && crcType <= CRCType.CRC32_MPEG2)
                    {
                        checkResult = DataCheck.GetCRC32(crcInfo, _DataBytes);
                        dataWidth   = 32;
                    }
                }

                CheckResultValue = checkResult;
                txtResult.Text   = getStringByUint32(CheckResultValue, chkIsLittleEndian.Checked, dataWidth);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }