public void CancelCommand()
 {
     if (_socketInProgress.HasValue && _sendQueueCommandInProgress != null && _sendQueueCommandInProgress.IsCommand)
     {
         logMessage(1, "Command '{0}' canceling on socket '{1}'", _sendQueueCommandInProgress.ToString(), _socketInProgress.Value);
         _sendData(new byte[] { (byte)(0x80 + _sendQueueCommandInProgress.Destination), (byte)(0x20 + _socketInProgress.Value), 0xFF });
     }
 }
        /// <summary>
        /// Sends the next queued command to the device
        /// </summary>
        private void sendNextQueuedCommand()
        {
            if (_sendQueue.Count > 0)
            {
                _sendQueueCommandInProgress = _sendQueue.Dequeue();
                logMessage(1, "Command '{0}' Dequeued. CommandQueue Size: {1}", _sendQueueCommandInProgress.ToString(), _sendQueue.Count);
                // start the timer to expire current command in case of no response
#if SSHARP
                _sendQueueItemInProgressTimer.Reset(_commandTimeOut);
#else
                _sendQueueItemInProgressTimer.Change(_commandTimeOut, Timeout.Infinite);
#endif
                _sendData(_sendQueueCommandInProgress);
            }
        }
        public void EnqueueCommand(ViscaTxPacket command)
        {
            // check for existing command in the Queue
            bool commandIsEnqueued = false;

            foreach (var sendQueueItem in _sendQueue)
            {
                //if (sendQueueItem.Packet == command)
                if (sendQueueItem == command)
                {
                    commandIsEnqueued = true;
                    break;
                }
            }

            if (commandIsEnqueued)
            {
                logMessage(1, "Enqueueing command '{0}' is duplicate, skipping. CommandQueue Size: '{1}'", command.ToString(), _sendQueue.Count);
                logMessage(2, "CommandQueue:");
                foreach (var sendQueueItem in _sendQueue)
                {
                    logMessage(2, "\t'{0}'", sendQueueItem.ToString());
                }
            }
            else
            {
                // If command is ViscaDynamicCommand, clone it to get static version for enquing
                if (command is ViscaDynamicCommand)
                {
                    command = (command as ViscaDynamicCommand).Clone();
                }
                _sendQueue.Enqueue(command);
                logMessage(1, "Enqueued command '{0}'. CommandQueue Size: '{1}'", command.ToString(), _sendQueue.Count);
            }

            if (_sendQueueCommandInProgress == null && (_responseQueue.Count == 0))
            {
                sendNextQueuedCommand();
            }
        }