public async Task <List <byte> > GetBytes() { await Task.Yield(); var data = new List <byte>(); data.AddRange(await GetCommandSection()); data.AddRange(await GetDataSection()); data.InsertRange(0, await GetHeaderSection(data.Count)); data.AddRange(GetBytes(MessageCrc.Get(data))); return(data); }
public void VerifyCrc() { var messageBytes = Bytes.SkipLast(4); var messageCrcBytes = Bytes.TakeLast(4).ToArray(); var crc = MessageCrc.Get(messageBytes); var crcBytes = BitConverter.GetBytes(crc); if (BitConverter.IsLittleEndian) { Array.Reverse(crcBytes); } for (var i = 0; i < 4; i++) { if (messageCrcBytes[i] != crcBytes[i]) { throw new InvalidReplyException($"CRC does not match."); } } }