예제 #1
0
        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);
            }
        }
예제 #2
0
        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();
            }
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        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();
            }
        }
예제 #5
0
        /// <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);
        }
예제 #6
0
 private bool checkBoundaries(InstructionCNC instruction, ref StateInfo state)
 {
     state.Accept(instruction);
     return(state.CheckBoundaries());
 }