示例#1
0
        public static string GetHexCheckSum(byte[] bytes, bool includeCheckSum = true)
        {
            int sum           = 0;
            int packagelength = bytes.Length;

            if (includeCheckSum)
            {
                packagelength = bytes.Length - 1;
            }

            for (int i = 0; i < packagelength; i++)
            {
                sum += DataHelper.ConvertToIntFromHex(bytes[i].ToString("X2"));
            }
            var actualCheckSum = DataHelper.ConvertToHexFromInt(sum);

            byte[] checksumBytes = DataHelper.HexStrTobyte(actualCheckSum);

            var temp = checksumBytes[checksumBytes.Length - 1].ToString("X2");

            return(temp);
        }
示例#2
0
        public byte[] GetCommandBytes()
        {
            var checkSum = DataHelper.GetHexCheckSum(DataHelper.HexStrTobyte(_hexString), false);

            return(DataHelper.HexStrTobyte(_hexString + checkSum));
        }