private void instructionCompleted() { InstructionCNC instruction; lock (_L_instructionQueue) { if (_queuedInstructions.Count == 0) { //probably garbage from buffer return; } --_bufferedInstructionCount; instruction = _queuedInstructions.Dequeue(); _lastInstructionStartTime = DateTime.Now; _uEstimation = _vEstimation = _xEstimation = _yEstimation = 0; _currentState.Accept(instruction); if (_queuedInstructions.Count == 0) { OnInstructionQueueIsComplete?.Invoke(); } Monitor.Pulse(_L_instructionQueue); } }
private void runCncSimulator() { IsConnected = true; _plannedState.Accept(new HomingInstruction()); _currentState.Accept(new HomingInstruction()); var simulationDelay = 10; var schedulerStopped = true; while (true) { if (_queuedInstructions.Count > 0) { schedulerStopped = false; InstructionCNC instruction; lock (_L_instructionQueue) { _lastInstructionStartTime = DateTime.Now; instruction = _queuedInstructions.Peek(); } var tickCount = instruction.CalculateTotalTime(); var time = 1000.0 * tickCount / Configuration.TimerFrequency; if (SIMULATE_REAL_DELAY) { Thread.Sleep((int)Math.Round(time)); } else { Thread.Sleep(200); } lock (_L_instructionQueue) { instructionCompleted(); if (LOG_STEPS) { StepLogger.LogInstruction(instruction); } if (_queuedInstructions.Count == 0 && OnInstructionQueueIsComplete != null) { OnInstructionQueueIsComplete(); } } } else { if (!schedulerStopped) { schedulerStopped = true; logSchedulerStop(); } Thread.Sleep(10); } } }
/// <summary> /// HAS TO BE CALLED WITH _L_instrutionCompletition /// </summary> private void onInstructionCompleted() { var now = DateTime.Now; _lastInstructionStartTime = now; _uEstimation = _vEstimation = _xEstimation = _yEstimation = 0; if (_incompleteInstructionQueue.Count == 0) { //TODO probably garbage from buffer return; } var instruction = _incompleteInstructionQueue.Dequeue(); _currentState.Accept(instruction); --_incompleteInstructions; }
private void runCncSimulator() { IsConnected = true; fireOnConnectionStatusChange(); _plannedState.Accept(new HomingInstruction()); _currentState.Accept(new HomingInstruction()); var simulationDelay = 10; while (true) { Thread.Sleep(simulationDelay); if (_incompleteInstructionQueue.Count > 0) { InstructionCNC instruction; lock (_L_instructionCompletition) { _lastInstructionStartTime = DateTime.Now; instruction = _incompleteInstructionQueue.Peek(); } var tickCount = instruction.CalculateTotalTime(); var time = 1000.0 * tickCount / Configuration.TimerFrequency; if (SIMULATE_REAL_DELAY) { Thread.Sleep((int)Math.Max(0, (long)time - (long)simulationDelay)); } else { Thread.Sleep(200); } lock (_L_instructionCompletition) { onInstructionCompleted(); if (_incompleteInstructionQueue.Count == 0 && OnInstructionQueueIsComplete != null) { OnInstructionQueueIsComplete(); } } } } }
private bool checkBoundaries(InstructionCNC instruction, ref StateInfo state) { state.Accept(instruction); return(state.CheckBoundaries()); }