/// <summary> Queue the send command wrapped in a command strategy. </summary> /// <param name="commandStrategy"> The command strategy. </param> public override void QueueCommand(CommandStrategy commandStrategy) { while (Queue.Count > MaxQueueLength) { Thread.Yield(); } lock (Queue) { // Process commandStrategy enqueue associated with command commandStrategy.CommandQueue = Queue; commandStrategy.Command.CommunicationManager = _communicationManager; ((SendCommand)commandStrategy.Command).InitArguments(); commandStrategy.Enqueue(); // Process all generic enqueue strategies foreach (var generalStrategy in GeneralStrategies) { generalStrategy.OnEnqueue(); } } SignalWorker(); }
/// <summary> Queue the command wrapped in a command strategy. </summary> /// <param name="commandStrategy"> The command strategy. </param> public override void QueueCommand(CommandStrategy commandStrategy) { if (IsSuspended) { // Directly send this command to waiting thread var addToQueue = _receivedCommandSignal.ProcessCommand((ReceivedCommand)commandStrategy.Command); // check if the item needs to be added to the queue for later processing. If not return directly if (!addToQueue) { return; } } lock (Queue) { // Process all generic enqueue strategies Queue.Enqueue(commandStrategy); foreach (var generalStrategy in GeneralStrategies) { generalStrategy.OnEnqueue(); } } if (!IsSuspended) { // Give a signal to indicate that a new item has been queued SignalWorker(); if (NewLineReceived != null) { NewLineReceived(this, new CommandEventArgs(commandStrategy.Command)); } } }
/// <summary> Sends the commands from queue. All commands will be combined until either /// the SendBufferMaxLength has been reached or if a command requires an acknowledge /// </summary> private void SendCommandsFromQueue() { _commandCount = 0; _sendBuffer = string.Empty; CommandStrategy eventCommandStrategy = null; // while maximum buffer string is not reached, and command in queue while (_sendBuffer.Length < _sendBufferMaxLength && Queue.Count > 0) { lock (Queue) { var commandStrategy = !IsEmpty?Queue.Peek() : null; if (commandStrategy != null) { if (commandStrategy.Command != null) { var sendCommand = (SendCommand)commandStrategy.Command; if (sendCommand.ReqAc) { if (_commandCount > 0) { break; } SendSingleCommandFromQueue(commandStrategy); } else { eventCommandStrategy = commandStrategy; AddToCommandString(commandStrategy); } } } } // event callback outside lock for performance if (eventCommandStrategy != null) { if (NewLineSent != null) { NewLineSent(this, new CommandEventArgs(eventCommandStrategy.Command)); } eventCommandStrategy = null; } } // Now check if a command string has been filled if (_sendBuffer.Length > 0) { _communicationManager.ExecuteSendString(_sendBuffer, SendQueue.InFrontQueue); } }
/// <summary> Sends a float command from the queue. </summary> /// <param name="commandStrategy"> The command strategy to send. </param> private void SendSingleCommandFromQueue(CommandStrategy commandStrategy) { // Dequeue lock (Queue) { commandStrategy.DeQueue(); // Process all generic dequeue strategies foreach (var generalStrategy in GeneralStrategies) { generalStrategy.OnDequeue(); } } // Send command if (commandStrategy.Command != null) { _communicationManager.ExecuteSendCommand((SendCommand)commandStrategy.Command, SendQueue.InFrontQueue); } }
/// <summary> Adds a commandStrategy to the commands string. </summary> /// <param name="commandStrategy"> The command strategy to add. </param> private void AddToCommandString(CommandStrategy commandStrategy) { // Dequeue lock (Queue) { commandStrategy.DeQueue(); // Process all generic dequeue strategies foreach (var generalStrategy in GeneralStrategies) { generalStrategy.OnDequeue(); } } // Add command if (commandStrategy.Command != null) { _commandCount++; _sendBuffer += commandStrategy.Command.CommandString(); if (_communicationManager.PrintLfCr) { _sendBuffer += "\r\n"; } } }
/// <summary> Queue the command wrapped in a command strategy. </summary> /// <param name="commandStrategy"> The command strategy. </param> public override void QueueCommand(CommandStrategy commandStrategy) { if (IsSuspended) { // Directly send this command to waiting thread var addToQueue = _receivedCommandSignal.ProcessCommand((ReceivedCommand)commandStrategy.Command); // check if the item needs to be added to the queue for later processing. If not return directly if (!addToQueue) return; } lock (Queue) { // Process all generic enqueue strategies Queue.Enqueue(commandStrategy); foreach (var generalStrategy in GeneralStrategies) { generalStrategy.OnEnqueue(); } } if (!IsSuspended) { // Give a signal to indicate that a new item has been queued SignalWorker(); if (NewLineReceived != null) NewLineReceived(this, new CommandEventArgs(commandStrategy.Command)); } }
/// <summary> /// Queue the command wrapped in a command strategy. /// Call SignalWaiter method to continue processing of queue. /// </summary> /// <param name="commandStrategy"> The command strategy. </param> public abstract void QueueCommand(CommandStrategy commandStrategy);
/// <summary> Sends a float command from the queue. </summary> /// <param name="commandStrategy"> The command strategy to send. </param> private void SendSingleCommandFromQueue(CommandStrategy commandStrategy) { // Dequeue lock (Queue) { commandStrategy.DeQueue(); // Process all generic dequeue strategies foreach (var generalStrategy in GeneralStrategies) { generalStrategy.OnDequeue(); } } // Send command if (commandStrategy.Command != null) _communicationManager.ExecuteSendCommand((SendCommand)commandStrategy.Command, SendQueue.InFrontQueue); }