资源简介

很优秀的串口调试助手代码

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;

namespace MySSCOM
{
    internal class CheckTransportProtocol
    {
        private uint Checksum
        {
            get
            {
                return this.checksum;
            }
            set
            {
                this.checksum = value;
            }
        }

        public List ArrByte
        {
            get
            {
                return this.arrByte;
            }
            set
            {
                this.arrByte = value;
            }
        }

        public CheckTransportProtocol()
        {
            this.arrByte = new List();
        }

        private void xorChecksum()
        {
            if (this.arrByte.Capacity == 0)
            {
                return;
            }
            this.Checksum = 0u;
            byte b = (byte)(this.arrByte[0] ^ this.arrByte[1]);
            for (int i = 2; i < this.arrByte.Count; i++)
            {
                b ^= this.arrByte[i];
            }
            this.Checksum = (uint)b;
        }

        private void sumChecksum()
        {
            if (this.arrByte.Capacity == 0)
            {
                return;
            }
            this.Checksum = 0u;
            byte b = 0;
            for (int i = 0; i < this.arrByte.Count; i++)
            {
                b += this.arrByte[i];
            }
            b = (byte)(256 - (int)b % 256);
            this.Checksum = (uint)b;
        }

        private void crc8Checksum()
        {
            if (this.arrByte.Capacity == 0)
            {
                return;
            }
            this.Checksum = 0u;
            byte b = 0;
            for (int i = 0; i < this.arrByte.Count; i++)
            {
                b = this.CRC8Table[(int)(b ^ this.arrByte[i])];
            }
            this.Checksum = (uint)b;
        }

        private void crc16Checksum()
        {
            if (this.arrByte.Capacity == 0)
            {
                return;
            }
            this.Checksum = 0u;
            byte b = byte.MaxValue;
            byte b2 = byte.MaxValue;
            for (int i = 0; i < this.arrByte.Count; i++)
            {
                int num = (int)(b2 ^ this.arrByte[i]);
                b2 = (byte)(b ^ this.auchCRCHi[num]);
                b = this.auchCRCLo[num];
            }
            this.Checksum += (uint)b2;
            this.Checksum <<= 8;
            this.Checksum += (uint)b;
        }

        public uint calculateChecksum(int checkType)
        {
            switch (checkType)
            {
                case 1:
                    this.Checksum = 0u;
                    break;
                case 2:
                    this.xorChecksum();
                    break;
                case 3:
                    this.sumChecksum();
                    break;
                case 4:
   

评论

共有 条评论