private void send(InstructionCNC instruction) { var data = new List <byte>(instruction.GetInstructionBytes()); while (data.Count < Configuration.InstructionLength - 2) { data.Add(0); } if (data.Count != Configuration.InstructionLength - 2) { throw new NotSupportedException("Invalid instruction length detected."); } //checksum is used for error detection Int16 checksum = 0; foreach (var b in data) { checksum += b; } data.AddRange(InstructionCNC.ToBytes(checksum)); var dataBuffer = data.ToArray(); lock (_L_instructionCompletition) { _incompleteInstructionQueue.Enqueue(instruction); } lock (_L_sendQueue) { _sendQueue.Enqueue(dataBuffer); Monitor.Pulse(_L_sendQueue); } }
internal void Completed(InstructionCNC instruction) { var homing = instruction as HomingInstruction; if (homing != null) { X = 0; Y = 0; U = 0; V = 0; TickCount = 0; IsHomeCalibrated = true; return; } var axesInstruction = instruction as Axes; if (axesInstruction != null) { if (axesInstruction.InstructionU != null) { U += axesInstruction.InstructionU.StepCount; } if (axesInstruction.InstructionV != null) { V += axesInstruction.InstructionV.StepCount; } if (axesInstruction.InstructionX != null) { X += axesInstruction.InstructionX.StepCount; } if (axesInstruction.InstructionY != null) { Y += axesInstruction.InstructionY.StepCount; } TickCount += axesInstruction.GetInstructionDuration(); return; } var stepInstruction = instruction as StepInstrution; if (stepInstruction != null) { X += stepInstruction.StepCount; TickCount += stepInstruction.GetInstructionDuration(); } }
/// <summary> /// Sends a given part to the machine. /// </summary> /// <param name="part">Part to send.</param> public bool SEND(InstructionCNC part) { var testState = _plannedState.Copy(); if (!checkBoundaries(part, ref testState)) { return(false); } _plannedState = testState; send(part); return(true); }
internal void Accept(InstructionCNC instruction) { var homing = instruction as HomingInstruction; if (homing != null) { calibrateHome(); return; } var axesInstruction = instruction as Axes; if (axesInstruction != null) { if (axesInstruction.InstructionU != null) { U += axesInstruction.InstructionU.HwStepCount; } if (axesInstruction.InstructionV != null) { V += axesInstruction.InstructionV.HwStepCount; } if (axesInstruction.InstructionX != null) { X += axesInstruction.InstructionX.HwStepCount; } if (axesInstruction.InstructionY != null) { Y += axesInstruction.InstructionY.HwStepCount; } TickCount += axesInstruction.GetInstructionDuration(); return; } var stepInstruction = instruction as StepInstrution; if (stepInstruction != null) { X += stepInstruction.HwStepCount; TickCount += stepInstruction.GetInstructionDuration(); } }
/// <summary> /// Sends a given part to the machine. /// </summary> /// <param name="instruction">Part to send.</param> public bool SEND(InstructionCNC instruction) { if (instruction.IsEmpty) { return(true); } var testState = _plannedState.Copy(); if (!checkBoundaries(instruction, ref testState)) { return(false); } _plannedState = testState; send(instruction); return(true); }
private bool checkBoundaries(InstructionCNC instruction, ref StateInfo state) { state.Accept(instruction); return(state.CheckBoundaries()); }