예제 #1
0
        bool InitSystem()
        {
            initOK = true;
            int timeout = 5;

            using (new UIUtils.WaitCursor())
            {
                GCodeSender.EnablePolling(false);
                while (!GrblInfo.Get())
                {
                    if (--timeout == 0)
                    {
                        model.Message = (string)FindResource("MsgNoResponse");
                        return(false);
                    }
                    Thread.Sleep(500);
                }
                GrblAlarms.Get();
                GrblErrors.Get();
                GrblSettings.Load();
                if (GrblInfo.IsGrblHAL)
                {
                    GrblParserState.Get();
                    GrblWorkParameters.Get();
                }
                else
                {
                    GrblParserState.Get(true);
                }
                GCodeSender.EnablePolling(true);
            }

            GrblCommand.ToolChange = GrblInfo.ManualToolChange ? "M61Q{0}" : "T{0}";

            showProgramLimits();

            if (!AppConfig.Settings.GCodeViewer.IsEnabled)
            {
                tabGCode.Items.Remove(tab3D);
            }

            if (GrblInfo.NumAxes > 3)
            {
                limitsControl.Visibility = Visibility.Collapsed;
            }

            if (GrblInfo.LatheModeEnabled)
            {
                MainWindow.EnableView(true, ViewType.Turning);
                //      MainWindow.EnableView(true, ViewType.Parting);
                //      MainWindow.EnableView(true, ViewType.Facing);
                MainWindow.EnableView(true, ViewType.G76Threading);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.Turning);
                MainWindow.ShowView(false, ViewType.Parting);
                MainWindow.ShowView(false, ViewType.Facing);
                MainWindow.ShowView(false, ViewType.G76Threading);
            }

            if (GrblInfo.HasSDCard)
            {
                MainWindow.EnableView(true, ViewType.SDCard);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.SDCard);
            }

            if (GrblInfo.HasPIDLog)
            {
                MainWindow.EnableView(true, ViewType.PIDTuner);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.PIDTuner);
            }

            if (GrblInfo.NumTools > 0)
            {
                MainWindow.EnableView(true, ViewType.Tools);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.Tools);
            }

            if (GrblInfo.HasProbe && GrblSettings.ReportProbeCoordinates)
            {
                MainWindow.EnableView(true, ViewType.Probing);
            }

            MainWindow.EnableView(true, ViewType.Offsets);
            MainWindow.EnableView(true, ViewType.GRBLConfig);

            if (!string.IsNullOrEmpty(GrblInfo.TrinamicDrivers))
            {
                MainWindow.EnableView(true, ViewType.TrinamicTuner);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.TrinamicTuner);
            }

            return(true);
        }
예제 #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);
        }
예제 #3
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);
        }
예제 #4
0
        private void InitSystem()
        {
            initOK = true;
            int timeout = 5;

            using (new UIUtils.WaitCursor())
            {
                GCodeSender.EnablePolling(false);
                while (!GrblInfo.Get())
                {
                    if (--timeout == 0)
                    {
                        model.Message = "Controller is not responding!";
                        initOK        = false;
                    }
                    Thread.Sleep(500);
                }
                GrblAlarms.Get();
                GrblErrors.Get();
                GrblSettings.Get();
                GrblParserState.Get();
                GrblWorkParameters.Get();
                GCodeSender.EnablePolling(true);
            }

            GrblCommand.ToolChange = GrblInfo.ManualToolChange ? "M61Q{0}" : "T{0}";

            if (keyboard == null)
            {
                keyboard = new KeypressHandler(model);
                GCodeSender.Configure(keyboard);
                gcodeRenderer.Configure();
            }

            showProgramLimits();

            if (!AppConfig.Settings.GCodeViewer.IsEnabled)
            {
                tabGCode.Items.Remove(tab3D);
            }

            if (GrblInfo.NumAxes > 3)
            {
                limitsControl.Visibility = Visibility.Collapsed;
            }

            if (GrblInfo.LatheModeEnabled)
            {
                MainWindow.EnableView(true, ViewType.Turning);
                //      MainWindow.EnableView(true, ViewType.Parting);
                //      MainWindow.EnableView(true, ViewType.Facing);
                MainWindow.EnableView(true, ViewType.G76Threading);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.Turning);
                MainWindow.ShowView(false, ViewType.Parting);
                MainWindow.ShowView(false, ViewType.Facing);
                MainWindow.ShowView(false, ViewType.G76Threading);
            }

            if (GrblInfo.HasSDCard)
            {
                MainWindow.EnableView(true, ViewType.SDCard);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.SDCard);
            }

            if (GrblInfo.HasPIDLog)
            {
                MainWindow.EnableView(true, ViewType.PIDTuner);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.PIDTuner);
            }

            if (GrblInfo.NumTools > 0)
            {
                MainWindow.EnableView(true, ViewType.Tools);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.Tools);
            }

            if (GrblInfo.HasProbe && GrblSettings.ReportProbeCoordinates)
            {
                MainWindow.EnableView(true, ViewType.Probing);
            }

            MainWindow.EnableView(true, ViewType.Offsets);
            MainWindow.EnableView(true, ViewType.GRBLConfig);

            if (!string.IsNullOrEmpty(GrblInfo.TrinamicDrivers))
            {
                MainWindow.EnableView(true, ViewType.TrinamicTuner);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.TrinamicTuner);
            }
        }