public string getHexStructureLine() { List <byte> hexLine = new List <byte>(); string hexStructureLine = ":"; hexLine.Add((byte)HexData.Length); byte[] add = BitConverter.GetBytes(Address); hexLine.Add(add[1]); hexLine.Add(add[0]); hexLine.Add(CheckCode); hexLine.AddRange(HexData); byte[] computeChkSumData = hexLine.ToArray(); byte computeChdSum = MassUtilityClass.CalculateHexChecksum8(computeChkSumData); hexLine.Add(computeChdSum); computeChkSumData = hexLine.ToArray(); hexStructureLine += MassUtilityClass.ByteArrayToHexString(computeChkSumData, false); return(hexStructureLine); }
public bool setHexStringLine(string HexLine) { string str = HexLine.Replace(':', ' ').Trim(); byte[] hexByte = MassUtilityClass.HexStringToByteArray(str); byte length = hexByte[0]; if ((length + 5) != hexByte.Length) { //fail length = 0; return(false); } //UInt16 address = BitConverter.ToUInt16(hexByte, 1); UInt16 address = hexByte[1]; address = (UInt16)((address * 256) + hexByte[2]); //byte[] add = BitConverter.GetBytes(address); byte checkCode = hexByte[3]; byte[] data = new byte[length]; Array.Copy(hexByte, 4, data, 0, length); byte ChkSum8 = hexByte[hexByte.Length - 1]; byte[] computeChkSumData = new byte[hexByte.Length - 1]; Array.Copy(hexByte, 0, computeChkSumData, 0, computeChkSumData.Length); byte computeChdSum = MassUtilityClass.CalculateHexChecksum8(computeChkSumData); if (ChkSum8 != computeChdSum) { return(false); } Address = address; CheckCode = checkCode; HexData = data; return(true); }