Ejemplo n.º 1
0
        /// <summary>
        /// This will interrupt the current movement, wait until it has stopped, and then
        /// end when the movement has stopped.
        ///
        /// If no motors are moving when this is called, then it will not wait, and just be
        /// able to pass through.
        /// </summary>
        /// <returns>True if it had to wait for a movement, false if it did not have to wait and there is no movement running.</returns>
        public override bool InterruptMovementAndWaitUntilStopped()
        {
            bool motorsMoving = MCU.MotorsCurrentlyMoving();

            if (motorsMoving && CurrentMovementPriority != MovementPriority.None)
            {
                logger.Info(Utilities.GetTimeStamp() + ": Overriding current movement...");
                MCU.MovementInterruptFlag = true;

                // Wait until motors stop moving or the interrupt flag is set back to false,
                // meaning the MCU has acknowledged and acted on the interrupt.
                while (MotorsCurrentlyMoving() && MCU.MovementInterruptFlag == true)
                {
                    ;
                }

                MCU.MovementInterruptFlag = false;

                // Ensure there is plenty of time between MCU commands
                Thread.Sleep(2000);
            }
            else
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// This will interrupt the current movement, wait until it has stopped, and then
        /// end when the movement has stopped.
        ///
        /// If no motors are moving when this is called, then it will not wait, and just be
        /// able to pass through.
        /// </summary>
        /// <param name="isCriticalMovementInterrupt">Specify whether or not this is a critical movement interrupt and perform and immediate stop</param>
        /// <param name="isSoftwareStopInterrupt">Specify whether or not this is a software-stop interrupt</param>
        /// <returns>True if it had to wait for a movement, false if it did not have to wait and there is no movement running.</returns>
        public override bool InterruptMovementAndWaitUntilStopped(bool isCriticalMovementInterrupt = false, bool isSoftwareStopInterrupt = false)
        {
            bool motorsMoving = MCU.MotorsCurrentlyMoving();

            if (motorsMoving && CurrentMovementPriority != MovementPriority.None)
            {
                logger.Info(Utilities.GetTimeStamp() + ": Overriding current movement...");
                MCU.MovementInterruptFlag = true;

                // Set corresponding flag depending on whether or not this is a critical movement interrupt
                if (isCriticalMovementInterrupt)
                {
                    MCU.CriticalMovementInterruptFlag = true;
                }

                // Set corresponding flag depending on whether or not this is a software stop interrupt
                if (isSoftwareStopInterrupt)
                {
                    // Currently necessary to stop Jog movements. Setting the SoftwaeStopInterruptFlag does not
                    // interrupt Jog movements. This should be investigated in the future.
                    if (CurrentMovementPriority == MovementPriority.Jog)
                    {
                        ImmediateStop();
                    }
                    MCU.SoftwareStopInterruptFlag = true;
                }

                // Wait until motors stop moving or all interrupt flags are set back to false,
                // meaning the MCU has acknowledged and acted on the interrupt.
                while (MotorsCurrentlyMoving() && (MCU.MovementInterruptFlag == true || MCU.CriticalMovementInterruptFlag == true || MCU.SoftwareStopInterruptFlag == true))
                {
                    ;
                }

                MCU.MovementInterruptFlag         = false;
                MCU.CriticalMovementInterruptFlag = false;
                MCU.SoftwareStopInterruptFlag     = false;

                // Ensure there is plenty of time between MCU commands
                Thread.Sleep(2000);
            }
            else
            {
                return(false);
            }

            return(true);
        }