public bool GotoMachinePosition(Position pos, AxisFlags axisflags)
        {
            bool?res  = null;
            bool wait = true;

            string command = "G53G0" + pos.ToString(axisflags);

            Comms.com.PurgeQueue();

            new Thread(() =>
            {
                res = WaitFor.AckResponse <string>(
                    cancellationToken,
                    null,
                    a => Grbl.OnResponseReceived += a,
                    a => Grbl.OnResponseReceived -= a,
                    100, () => Grbl.ExecuteCommand(command));
            }).Start();

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

            if (res == true)
            {
                while (wait && !isCancelled)
                {
                    res = null;

                    new Thread(() =>
                    {
                        res = WaitFor.SingleEvent <string>(
                            cancellationToken,
                            null,
                            a => Grbl.OnRealtimeStatusProcessed += a,
                            a => Grbl.OnRealtimeStatusProcessed -= a,
                            200, () => Comms.com.WriteByte(GrblLegacy.ConvertRTCommand(GrblConstants.CMD_STATUS_REPORT)));
                    }).Start();

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

                    wait = res != true;

                    int i = 0, axes = (int)axisflags;
                    while (axes != 0 && !wait)
                    {
                        if ((axes & 0x01) != 0)
                        {
                            wait = Math.Abs(pos.Values[i] - Grbl.MachinePosition.Values[i]) >= 0.003d; // use step resolution plus some?
                        }
                        i++; axes >>= 1;
                    }

                    if (wait)
                    {
                        Thread.Sleep(200); // needed?
                    }
                }
            }

            return(isCancelled ? false : !wait);
        }
Exemple #2
0
        public bool GotoMachinePosition(Position pos, AxisFlags axisflags)
        {
            bool?  res = null;
            bool   wait = true, running = false;
            double delta, delta_max = 0d;

            string command = "G53" + RapidCommand + pos.ToString(axisflags);

            Comms.com.PurgeQueue();

            Grbl.Poller.SetState(0);

            new Thread(() =>
            {
                res = WaitFor.AckResponse <string>(
                    cancellationToken,
                    null,
                    a => Grbl.OnResponseReceived += a,
                    a => Grbl.OnResponseReceived -= a,
                    1000, () => Grbl.ExecuteCommand(command));
            }).Start();

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

            if (res == true)
            {
                while (wait && !isCancelled)
                {
                    res = null;

                    new Thread(() =>
                    {
                        res = WaitFor.SingleEvent <string>(
                            cancellationToken,
                            null,
                            a => Grbl.OnRealtimeStatusProcessed += a,
                            a => Grbl.OnRealtimeStatusProcessed -= a,
                            400, () => Comms.com.WriteByte(GrblLegacy.ConvertRTCommand(GrblConstants.CMD_STATUS_REPORT)));
                    }).Start();

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

                    wait     = res != true;
                    running |= Grbl.GrblState.State == GrblStates.Run;

                    int i = 0, axes = (int)axisflags;
                    while (axes != 0 && !wait)
                    {
                        if ((axes & 0x01) != 0)
                        {
                            delta     = Math.Abs(pos.Values[i] - Grbl.MachinePosition.Values[i]);
                            wait      = delta > Math.Max(0.003d, GrblInfo.TravelResolution.Values[i] * 2d);
                            delta_max = Math.Max(delta, delta_max);
                            if (wait && Grbl.GrblState.State == GrblStates.Idle && (running || delta_max < 0.01d))
                            {
                                wait        = false;
                                isCancelled = true;
                            }
                        }
                        i++; axes >>= 1;
                    }

                    if (wait)
                    {
                        Thread.Sleep(AppConfig.Settings.Base.PollInterval); // needed?
                    }
                }
            }

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

            return(isCancelled ? false : !wait);
        }
Exemple #3
0
        public bool Init()
        {
            bool?res = null;

            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)
            {
                Message = GrblAlarms.GetMessage(Grbl.GrblState.Substate.ToString());
                res     = false;
            }

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

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

            Program.Clear();

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

            return(res == true);
        }