private static void VerifyPec(byte[] buffer, int start, int length)
        {
            if (buffer.Length < start + length)
            {
                throw new InvalidOperationException("The PEC byte is missing in source data.");
            }

            if (PecCalculator.CalculatePec(buffer, start, length) != 0)
            {
                throw new CommunicationException("The Packet Error Code check failed.");
            }
        }
        public Task SendByte(byte address, byte data)
        {
            var buffer = new byte[3];

            buffer[0] = GetAddressByte(address, false);
            buffer[1] = data;
            buffer[2] = PecCalculator.CalculatePec(buffer, 0, 2);

            var sendBuffer = new byte[2];

            Array.Copy(buffer, 1, sendBuffer, 0, sendBuffer.Length);

            return(Bus.Send(address, sendBuffer));
        }
        private Task WriteValueCommand(byte address, byte commandId, byte[] data)
        {
            var buffer = new byte[2 + data.Length + 1];

            buffer[0] = GetAddressByte(address, false);
            buffer[1] = commandId;
            data.CopyTo(buffer, 2);
            buffer[2 + data.Length] = PecCalculator.CalculatePec(buffer, 0, 2 + data.Length);

            var sendBuffer = new byte[1 + data.Length + 1];

            Array.Copy(buffer, 1, sendBuffer, 0, sendBuffer.Length);

            return(Bus.Send(address, sendBuffer));
        }