/// <summary> Directly executes the send command operation. </summary> /// <param name="sendCommand"> The command to sent. </param> /// <param name="sendQueueState"> Property to optionally clear the send and receive queues. </param> /// <returns> A received command. The received command will only be valid if the ReqAc of the command is true. </returns> public ReceivedCommand ExecuteSendCommand(SendCommand sendCommand, SendQueue sendQueueState) { // Disable listening, all callbacks are disabled until after command was sent ReceivedCommand ackCommand; lock (_sendCommandDataLock) { sendCommand.CommunicationManager = this; sendCommand.InitArguments(); if (sendCommand.ReqAc) { // Stop processing receive queue before sending. Wait until receive queue is actualy done _receiveCommandQueue.Suspend(); } if (sendCommand.ReqAc) { _receiveCommandQueue.PrepareForCmd(sendCommand.AckCmdId, sendQueueState); WriteCommand(sendCommand); var rc = BlockedTillReply(sendCommand.Timeout); ackCommand = rc ?? new ReceivedCommand(); } else { WriteCommand(sendCommand); ackCommand = new ReceivedCommand(); } ackCommand.CommunicationManager = this; } if (sendCommand.ReqAc) { // Stop processing receive queue before sending _receiveCommandQueue.Resume(); } return(ackCommand); }