Example #1
0
        public bool Init()
        {
            bool?res = null;

            probing.Message = String.Empty;

            Grbl.Poller.SetState(0);  // Disable status polling during probing

            // Clear error status if set
            if (Grbl.GrblError != 0)
            {
                new Thread(() =>
                {
                    res = WaitFor.AckResponse <string>(
                        cancellationToken,
                        null,
                        a => Grbl.OnResponseReceived += a,
                        a => Grbl.OnResponseReceived -= a,
                        1000, () => Grbl.ExecuteCommand(""));
                }).Start();

                while (res == null)
                {
                    EventUtils.DoEvents();
                }

                res = null;
            }

            // Get a status report in order to establish current machine position
            new Thread(() =>
            {
                res = WaitFor.SingleEvent <string>(
                    cancellationToken,
                    null,
                    a => Grbl.OnResponseReceived += a,
                    a => Grbl.OnResponseReceived -= a,
                    1000, () => Comms.com.WriteByte(GrblLegacy.ConvertRTCommand(GrblConstants.CMD_STATUS_REPORT)));
            }).Start();

            while (res == null)
            {
                EventUtils.DoEvents();
            }

            Grbl.Poller.SetState(AppConfig.Settings.Base.PollInterval);

            if (Grbl.GrblState.State == GrblStates.Alarm)
            {
                probing.Message = GrblAlarms.GetMessage(Grbl.GrblState.Substate.ToString());
                res             = false;
            }

            if (res == true && Grbl.Signals.Value.HasFlag(Signals.ProbeDisconnected))
            {
                probing.Message = "Probing failed, probe is not connected";
                res             = false;
            }

            if (res == true && Grbl.Signals.Value.HasFlag(Signals.Probe))
            {
                probing.Message = "Probing failed, probe signal is asserted";
                res             = false;
            }

            if (res == true && !(Grbl.GrblState.State == GrblStates.Idle || Grbl.GrblState.State == GrblStates.Tool))
            {
                probing.Message = "Probing failed, Grbl is not in idle or tool changing state";
                res             = false;
            }

            if (res == true && !Grbl.IsMachinePositionKnown)
            {
                probing.Message = "Probing failed, could not establish current machine position";
                res             = false;
            }

            _program.Clear();

            if (res != true) // Reenable status polling if init fails
            {
                Grbl.Poller.SetState(AppConfig.Settings.Base.PollInterval);
            }

            return(res == true);
        }
Example #2
0
        public bool Init(bool check_probe = true)
        {
            bool?res = null;

            IsCancelled     = false;
            probing.Message = string.Empty;

            Grbl.Poller.SetState(0);  // Disable status polling during initialization

            // Clear error status if set
            if (Grbl.GrblError != 0)
            {
                new Thread(() =>
                {
                    res = WaitFor.AckResponse <string>(
                        cancellationToken,
                        null,
                        a => Grbl.OnResponseReceived += a,
                        a => Grbl.OnResponseReceived -= a,
                        1000, () => Grbl.ExecuteCommand(""));
                }).Start();

                while (res == null)
                {
                    EventUtils.DoEvents();
                }

                res = null;
            }

            // Get a status report in order to establish current machine position
            new Thread(() =>
            {
                res = WaitFor.SingleEvent <string>(
                    cancellationToken,
                    null,
                    a => Grbl.OnResponseReceived += a,
                    a => Grbl.OnResponseReceived -= a,
                    AppConfig.Settings.Base.PollInterval * 5, () => Comms.com.WriteByte(GrblInfo.IsGrblHAL ? GrblConstants.CMD_STATUS_REPORT_ALL : GrblLegacy.ConvertRTCommand(GrblConstants.CMD_STATUS_REPORT)));
            }).Start();

            while (res == null)
            {
                EventUtils.DoEvents();
            }

            Grbl.Poller.SetState(AppConfig.Settings.Base.PollInterval);

            if (Grbl.GrblState.State == GrblStates.Alarm)
            {
                probing.Message = GrblAlarms.GetMessage(Grbl.GrblState.Substate.ToString());
                res             = false;
            }

            if (res == true && check_probe)
            {
                res = IsProbeReady(false);
            }

            if (res == true && !(Grbl.GrblState.State == GrblStates.Idle || Grbl.GrblState.State == GrblStates.Tool))
            {
                probing.Message = LibStrings.FindResource("FailedNotIdle");
                res             = false;
            }

            if (res == true && !Grbl.IsMachinePositionKnown)
            {
                probing.Message = LibStrings.FindResource("FailedNoPos");
                res             = false;
            }

            probing.StartPosition.Set(probing.Grbl.MachinePosition);

            hasPause = probeOnCycleStart = false;
            _program.Clear();

            return(res == true);
        }