/// <summary>
        /// Send frame bytes to serial, and wait respond.
        /// </summary>
        /// <param name="bytes">Bytes to sent</param>
        /// <exception cref="SerialDeviceException"> If timeout or exceed maximum number of retries.</exception>
        public Task SendFrame(SerialCommandFrame frame)
        {
            if (_senderTasks.Count > MaxNumQueuedTask)
            {
                throw new SerialDeviceException($"Too many frames ({_senderTasks.Count}) queued!");
            }

            SenderTask task = new SenderTask(frame);

            if (!ValidFrameBytes(task.BytesToSend))
            {
                throw new ArgumentException("Invalid frame bytes!");
            }

            _senderTasks.Enqueue(task);
            _threadTrigger.Set();

            return(task.AwaitSource.Task);
        }
 public SenderTask(SerialCommandFrame frame)
 {
     AwaitSource = new TaskCompletionSource();
     Original    = frame;
     BytesToSend = frame.Bytes;
 }