}                                //TODO "Fix axis errors" button, to reset the axis counting

        private bool waitForHomingStop() //Must run when isHoming = true, but return false if port closes.
        {
            if (!serial.IsOpen)
            {
                return(false);
            }
            while (true)
            {
                //Read status
                IStageCommand statusCMD = new Commands.Status(1);
                if (!sendCommand(statusCMD))
                {
                    return(false);
                }
                string response = null;
                if (!readLine(out response))
                {
                    return(false);
                }
                object obj = statusCMD.ParseResponse(response);
                if ((obj == null) || !(obj is Commands.StageStatus))
                {
                    return(false);
                }
                Commands.StageStatus status = (Commands.StageStatus)obj;
                if (status.Stopped)
                {
                    return(true);
                }

                //Wait to check status again.
                Thread.Sleep(100);
            }
        }
Beispiel #2
0
        /// <summary>Reads and displays stage any errors via Message boxes. Returns false if an error occured.
        /// ErrorsOccured = false if was able to read, but there were no errors.</summary>
        public bool DisplayStageErrors(out bool ErrorsOccured)
        {
            ErrorsOccured = true;
            IStageCommand statusCommand = new MotorizedStage.Commands.Status(1);

            MotorizedStage.Commands.StageStatus status;
            if (!stage.TrySendCommand(statusCommand, out status))
            {
                return(false);
            }
            if (!status.ErrorHasOccured)
            {
                ErrorsOccured = false;                 //No error has occured, so there is no need to check any further.
                return(true);
            }

            IStageCommand errorCommand = new MotorizedStage.Commands.ReadAndClearErrors(1);

            StageError[] errors;
            if (!stage.TrySendCommand(errorCommand, out errors))
            {
                return(false);
            }
            foreach (StageError error in errors)
            {
                MessageBox.Show("ERROR: " + error.Name + "; " + error.ShortDescription);
            }

            return(true);
        }
        public bool WaitForStop()
        {
            if (!serial.IsOpen || isHoming)
            {
                return(false);
            }
            while (true)
            {
                IStageCommand        command = new Commands.Status(1);
                Commands.StageStatus status;
                if (!TrySendCommand(command, out status))
                {
                    return(false);                                                      //Error reading status
                }
                if (status.Stopped)
                {
                    return(true);
                }

                //Wait to check again.
                Thread.Sleep(100);
            }
        }                                //TODO "Fix axis errors" button, to reset the axis counting