Ejemplo n.º 1
0
        public void Activate(bool activate, ViewType chgMode)
        {
            if (activate)
            {
                if (model.CoordinateSystems.Count == 0)
                {
                    //                   model.CoordinateSystems.Add(model.CoordinateSystem = new CoordinateSystem("Active", "0"));
                    foreach (var cs in GrblWorkParameters.CoordinateSystems)
                    {
                        if (cs.Id > 0 && cs.Id < 9)
                        {
                            model.CoordinateSystems.Add(new CoordinateSystem(cs.Code, "0"));
                        }

                        if (cs.Id == 9)
                        {
                            model.HasCoordinateSystem9 = true;
                        }
                    }
                    model.HasToolTable = GrblInfo.NumTools > 0;
                }

                GrblParserState.Get(!GrblSettings.IsGrblHAL);
                mode                   = GrblParserState.DistanceMode;
                model.Tool             = model.Grbl.Tool == GrblConstants.NO_TOOL ? "0" : model.Grbl.Tool;
                model.CanProbe         = !model.Grbl.Signals.Value.HasFlag(Signals.Probe);
                model.HeightMapApplied = GCode.File.HeightMapApplied;
                int csid = GrblWorkParameters.GetCoordinateSystem(model.Grbl.WorkCoordinateSystem).Id;
                model.CoordinateSystem = csid == 0 || csid >= 9 ? 1 : csid;

                if (model.Grbl.IsTloReferenceSet && !double.IsNaN(model.Grbl.TloReference))
                {
                    model.TloReference        = model.Grbl.TloReference;
                    model.ReferenceToolOffset = false;
                }

                model.Grbl.PropertyChanged += Grbl_PropertyChanged;

                probeTriggered = model.Grbl.Signals.Value.HasFlag(Signals.Probe);

                DisplayPosition(model.Grbl);
            }
            else
            {
                model.Grbl.PropertyChanged -= Grbl_PropertyChanged;

                // If probing alarm active unlock
                if (model.Grbl.GrblState.State == GrblStates.Alarm && (model.Grbl.GrblState.Substate == 4 || model.Grbl.GrblState.Substate == 5))
                {
                    model.Grbl.ExecuteCommand(GrblConstants.CMD_UNLOCK);
                }
                else if (model.Grbl.GrblError != 0)
                {
                    model.Grbl.ExecuteCommand("");  // Clear error
                }
                model.Grbl.ExecuteCommand(mode == DistanceMode.Absolute ? "G90" : "G91");
            }

            model.Grbl.Poller.SetState(activate ? AppConfig.Settings.Base.PollInterval : 0);
        }
Ejemplo n.º 2
0
        private void start_Click(object sender, RoutedEventArgs e)
        {
            var probing = DataContext as ProbingViewModel;

            if (!probing.Init())
            {
                return;
            }

            probing.PropertyChanged += Probing_PropertyChanged;

            probing.Program.Add(string.Format("G91F{0}", probing.ProbeFeedRate.ToInvariantString()));

            origin = new Position(probing.Grbl.MachinePosition);

            if (probing.ProbeFixture)
            {
                var g59_3 = GrblWorkParameters.GetCoordinateSystem("G59.3");
                g59_3.Z += probing.Offset.Z;
                probing.Program.Add("G53G0" + g59_3.ToString(AxisFlags.X | AxisFlags.Y));
                probing.Program.Add("G53G0" + g59_3.ToString(AxisFlags.Z));
            }
            probing.Program.Add(Probing.Command + probing.Distance.ToString(AxisFlags.Z, true));
            probing.Execute.Execute(true);
        }
Ejemplo n.º 3
0
        // G10 L1 P- axes <R- I- J- Q-> Set Tool Table
        // L10 - ref G5x + G92 - useful for probe (G38)
        // L11 - ref g59.3 only
        // Q: 1 - 8: 1: 135, 2: 45, 3: 315, 4: 225, 5: 180, 6: 90, 7: 0, 8: 270

        void saveOffset(string axis)
        {
            string cmd;

            Position newpos = new Position(Offset);

            newpos.X = GrblWorkParameters.ConvertX(GrblWorkParameters.LatheMode, GrblParserState.LatheMode, selectedOffset.X);

            if (selectedOffset.Id == 0)
            {
                string code = selectedOffset.Code == "G28" || selectedOffset.Code == "G30" ? selectedOffset.Code + ".1" : selectedOffset.Code;

                if (axis == "ClearAll" || IsPredefined)
                {
                    cmd = selectedOffset.Code + ".1";
                }
                else
                {
                    cmd = string.Format("G90{0}{1}", code, newpos.ToString(axis == "All" ? GrblInfo.AxisFlags : GrblInfo.AxisLetterToFlag(axis)));
                }
            }
            else
            {
                cmd = string.Format("G90G10L2P{0}{1}", selectedOffset.Id, newpos.ToString(axis == "All" || axis == "ClearAll" ? GrblInfo.AxisFlags : GrblInfo.AxisLetterToFlag(axis)));
            }

            Comms.com.WriteCommand(cmd);
        }
Ejemplo n.º 4
0
        // G10 L1 P- axes <R- I- J- Q-> Set Tool Table
        // L10 - ref G5x + G92 - useful for probe (G38)
        // L11 - ref g59.3 only
        // Q: 1 - 8: 1: 135, 2: 45, 3: 315, 4: 225, 5: 180, 6: 90, 7: 0, 8: 270

        void saveOffset(string axis)
        {
            string s, axes = string.Empty;

            string[] soffset = new string[6];

            if (axis == "All")
            {
                int i = 0, axisflags = GrblInfo.AxisFlags;
                while (axisflags != 0)
                {
                    if ((axisflags & 0x01) != 0)
                    {
                        axes += string.Format("{0}{{{1}}}", GrblInfo.AxisIndexToLetter(i), i + 1);
                    }
                    i++; axisflags >>= 1;
                }
            }
            else
            {
                axes = axis + "{" + (GrblInfo.AxisLetterToIndex(axis) + 1).ToString() + "}";
            }

            for (int i = 0; i < selectedOffset.Values.Length; i++)
            {
                if (i == 0)
                {
                    soffset[i] = GrblWorkParameters.ConvertX(GrblWorkParameters.LatheMode, GrblParserState.LatheMode, selectedOffset.X).ToInvariantString();
                }
                else
                {
                    soffset[i] = selectedOffset.Values[i].ToInvariantString();
                }
            }

            string xOffset = GrblWorkParameters.ConvertX(GrblWorkParameters.LatheMode, GrblParserState.LatheMode, selectedOffset.X).ToInvariantString();

            if (selectedOffset.Id == 0)
            {
                string code = selectedOffset.Code == "G28" || selectedOffset.Code == "G30" ? selectedOffset.Code + ".1" : selectedOffset.Code;
                s = string.Format("G90{0}" + axes, code, soffset[0], soffset[1], soffset[2], soffset[3], soffset[4], soffset[5]);
            }
            else
            {
                s = string.Format("G90G10L2P{0}" + axes, selectedOffset.Id, soffset[0], soffset[1], soffset[2], soffset[3], soffset[4], soffset[5]);
            }

            Comms.com.WriteCommand(s);
        }
Ejemplo n.º 5
0
        private void btnClearAll_Click(object sender, RoutedEventArgs e)
        {
            if (selectedTool != null)
            {
                for (var i = 0; i < offset.Values.Length; i++)
                {
                    offset.Values[i] = selectedTool.Values[i] = 0d;
                }

                string xOffset = GrblWorkParameters.ConvertX(GrblWorkParameters.LatheMode, GrblParserState.LatheMode, cvXOffset.Value).ToInvariantString();

                string s = string.Format("G10L1P{0}X{1}Y{2}Z{3}R{4}", selectedTool.Code, xOffset, cvYOffset.Text, cvZOffset.Text, cvTipRadius.Text);
                Comms.com.WriteCommand(s);
            }
        }
Ejemplo n.º 6
0
        public void Activate(bool activate, ViewType chgMode)
        {
            if (activate)
            {
                Comms.com.DataReceived += parameters.DataReceived;

                GrblWorkParameters.Get(parameters);

                dgrTools.ItemsSource   = new ObservableCollection <Tool>(from tool in GrblWorkParameters.Tools where tool.Code != GrblConstants.NO_TOOL orderby tool.Code select tool);
                dgrTools.SelectedIndex = 0;
            }
            else
            {
                Comms.com.DataReceived -= parameters.DataReceived;
                dgrTools.ItemsSource    = null;
            }
        }
        public void Activate(bool activate, ViewType chgMode)
        {
            if (activate)
            {
                GrblWorkParameters.Get();

                Comms.com.DataReceived += DataReceived;

                dgrOffsets.ItemsSource   = GrblWorkParameters.CoordinateSystems;
                dgrOffsets.SelectedIndex = 0;
            }
            else
            {
                Comms.com.DataReceived -= DataReceived;
                Comms.com.PurgeQueue();
                dgrOffsets.ItemsSource = null;
            }
        }
        // G10 L1 P- axes <R- I- J- Q-> Set Tool Table
        // L10 - ref G5x + G92 - useful for probe (G38)
        // L11 - ref g59.3 only
        // Q: 1 - 8: 1: 135, 2: 45, 3: 315, 4: 225, 5: 180, 6: 90, 7: 0, 8: 270

        void saveOffset(string axis)
        {
            string s;
            string axes    = axis == "All" ? "X{1}Y{2}Z{3}" : (axis + "{" + (GrblInfo.AxisLetterToIndex(axis) + 1).ToString() + "}");
            string xOffset = GrblWorkParameters.ConvertX(GrblWorkParameters.LatheMode, GrblParserState.LatheMode, selectedOffset.X).ToInvariantString();

            if (selectedOffset.Id == 0)
            {
                string code = selectedOffset.Code == "G28" || selectedOffset.Code == "G30" ? selectedOffset.Code + ".1" : selectedOffset.Code;
                s = string.Format("G90{0}" + axes, code, xOffset, selectedOffset.Y.ToInvariantString(), selectedOffset.Z.ToInvariantString());
            }
            else
            {
                s = string.Format("G90G10L2P{0}" + axes, selectedOffset.Id, xOffset, selectedOffset.Y.ToInvariantString(), selectedOffset.Z.ToInvariantString());
            }

            Comms.com.WriteCommand(s);
        }
Ejemplo n.º 9
0
        public void Activate(bool activate, ViewType chgMode)
        {
            if (activate)
            {
                GrblWorkParameters.Get();

                Comms.com.DataReceived += DataReceived;

                dgrTools.ItemsSource   = GrblWorkParameters.Tools;
                dgrTools.SelectedIndex = 0;
            }
            else
            {
                Comms.com.DataReceived -= DataReceived;

                dgrTools.ItemsSource = null;
            }
        }
Ejemplo n.º 10
0
        public void Start(bool preview = false)
        {
            var probing = DataContext as ProbingViewModel;

            if (!probing.ValidateInput())
            {
                return;
            }

            if (probing.ProbeFixture && probing.Grbl.HomedState != HomedState.Homed)
            {
                MessageBox.Show("Axes must be homed before probing the fixture!", "Probing");
                return;
            }

            if (!probing.Program.Init())
            {
                return;
            }

            probing.Program.Add(string.Format("G91F{0}", probing.ProbeFeedRate.ToInvariantString()));

            if (probing.ProbeFixture)
            {
                g59_3    = new Position(GrblWorkParameters.GetCoordinateSystem("G59.3"));
                safeZ    = new Position(probing.StartPosition);
                safeZ.Z  = System.Math.Max(g59_3.Z, probing.StartPosition.Z) + probing.Depth;
                g59_3.Z += probing.Depth;
                if (safeZ.Z < 0d)
                {
                    probing.Program.AddRapidToMPos(safeZ, AxisFlags.Z);
                }
                else
                {
                    safeZ.Z = g59_3.Z;
                }
                probing.Program.AddRapidToMPos(g59_3, AxisFlags.X | AxisFlags.Y);
                probing.Program.AddRapidToMPos(g59_3, AxisFlags.Z);
                g59_3.Z -= probing.Depth;
            }
            probing.Program.AddProbingAction(AxisFlags.Z, true);
            probing.Program.Execute(true);
            OnCompleted();
        }
Ejemplo n.º 11
0
        public void Activate(bool activate, ViewType chgMode)
        {
            if (activate)
            {
                if (model.CoordinateSystems.Count == 0)
                {
                    //                   model.CoordinateSystems.Add(model.CoordinateSystem = new CoordinateSystem("Active", "0"));
                    foreach (var cs in GrblWorkParameters.CoordinateSystems)
                    {
                        if (cs.Id > 0 && cs.Id < 9)
                        {
                            model.CoordinateSystems.Add(new CoordinateSystem(cs.Code, "0"));
                        }

                        if (cs.Id == 9)
                        {
                            model.HasCoordinateSystem9 = true;
                        }
                    }
                    model.HasToolTable = GrblInfo.NumTools > 0;
                }

                GrblParserState.Get();
                mode                   = GrblParserState.DistanceMode;
                model.Tool             = model.Grbl.Tool == GrblConstants.NO_TOOL ? "0" : model.Grbl.Tool;
                model.CanProbe         = !model.Grbl.Signals.Value.HasFlag(Signals.Probe);
                model.HeightMapApplied = GCode.File.HeightMapApplied;
                int csid = GrblWorkParameters.GetCoordinateSystem(model.Grbl.WorkCoordinateSystem).Id;
                model.CoordinateSystem = csid == 0 || csid >= 9 ? 1 : csid;

                model.Grbl.PropertyChanged += Grbl_PropertyChanged;
            }
            else
            {
                model.Grbl.PropertyChanged -= Grbl_PropertyChanged;
                if (model.Grbl.GrblError != 0)
                {
                    model.Grbl.ExecuteCommand("");  // Clear error
                }
                model.Grbl.ExecuteCommand(mode == DistanceMode.Absolute ? "G90" : "G91");
            }

            model.Grbl.Poller.SetState(activate ? AppConfig.Settings.Base.PollInterval : 0);
        }
Ejemplo n.º 12
0
        public void Activate(bool activate, ViewType chgMode)
        {
            if (activate)
            {
                Comms.com.DataReceived += parameters.DataReceived;

                GrblWorkParameters.Get(parameters);

                parameters.AxisEnabledFlags = GrblInfo.AxisFlags;

                dgrOffsets.ItemsSource   = GrblWorkParameters.CoordinateSystems;
                dgrOffsets.SelectedIndex = 0;
            }
            else
            {
                Comms.com.DataReceived -= parameters.DataReceived;
                Comms.com.PurgeQueue();
                dgrOffsets.ItemsSource = null;
            }
        }
Ejemplo n.º 13
0
        private void start_Click(object sender, RoutedEventArgs e)
        {
            var probing = DataContext as ProbingViewModel;

            if (!probing.ValidateInput())
            {
                return;
            }

            if (probing.ProbeFixture && probing.Grbl.HomedState != HomedState.Homed)
            {
                MessageBox.Show("Axes must be homed before probing the fixture!", "Probing");
                return;
            }

            if (!probing.Program.Init())
            {
                return;
            }

            probing.PropertyChanged += Probing_PropertyChanged;

            probing.Program.Add(string.Format("G91F{0}", probing.ProbeFeedRate.ToInvariantString()));

            origin = new Position(probing.Grbl.MachinePosition);

            if (probing.ProbeFixture)
            {
                g59_3 = new Position(GrblWorkParameters.GetCoordinateSystem("G59.3"));
                var safeZ = System.Math.Max(g59_3.Z, origin.Z) + probing.Depth;
                g59_3.Z += probing.Depth;
                probing.Program.Add("G53G0Z" + safeZ.ToInvariantString());
                probing.Program.Add("G53G0" + g59_3.ToString(AxisFlags.X | AxisFlags.Y));
                probing.Program.Add("G53G0" + g59_3.ToString(AxisFlags.Z));
                g59_3.Z -= probing.Depth;
            }
            probing.Program.AddProbingAction(AxisFlags.Z, true);
            probing.Program.Execute(true);
        }
Ejemplo n.º 14
0
        public void Start(bool preview = false)
        {
            var probing = DataContext as ProbingViewModel;

            if (!probing.ValidateInput(true))
            {
                return;
            }

            if (probing.ProbeFixture && !probing.Grbl.AxisHomed.Value.HasFlag(AxisFlags.X | AxisFlags.Y | AxisFlags.Z))
            {
                MessageBox.Show((string)FindResource("InitFailed"), "Probing");
                return;
            }

            if (!probing.Program.Init(AppConfig.Settings.Probing.CheckProbeStatus || !probing.ProbeFixture))
            {
                return;
            }

            probing.Program.Add(string.Format("G91F{0}", probing.ProbeFeedRate.ToInvariantString()));

            if (probing.ProbeFixture)
            {
                g59_3 = new Position(GrblWorkParameters.GetCoordinateSystem("G59.3"));
                double g59_3_Z = g59_3.Z;
                g59_3.Z = System.Math.Min(probing.Grbl.HomePosition.Z, g59_3.Z + probing.Depth);
                probing.Program.AddRapidToMPos(probing.Grbl.HomePosition, AxisFlags.Z);
                probing.Program.AddRapidToMPos(g59_3, AxisFlags.X | AxisFlags.Y);
                probing.Program.AddRapidToMPos(g59_3, AxisFlags.Z);
                g59_3.Z = g59_3_Z;
            }
            probing.Program.AddProbingAction(AxisFlags.Z, true);
            probing.Program.Execute(true);
            OnCompleted();
        }
Ejemplo n.º 15
0
        // G10 L1 P- axes <R- I- J- Q-> Set Tool Table
        // L10 - ref G5x + G92 - useful for probe (G38)
        // L11 - ref g59.3 only
        // Q: 1 - 8: 1: 135, 2: 45, 3: 315, 4: 225, 5: 180, 6: 90, 7: 0, 8: 270

        void saveOffset(string axis)
        {
            string   axes;
            Position newpos = new Position(offset);

            newpos.X = GrblWorkParameters.ConvertX(GrblWorkParameters.LatheMode, GrblParserState.LatheMode, selectedTool.X);

            switch (axis)
            {
            case "R":
                axes = "R{4}";
                break;

            case "All":
                axes = newpos.ToString(GrblInfo.AxisFlags);
                break;

            default:
                axes = newpos.ToString(GrblInfo.AxisLetterToFlag(axis));
                break;
            }

            Comms.com.WriteCommand(string.Format("G10L1P{0}{1}", selectedTool.Code, axes));
        }
Ejemplo n.º 16
0
        // G10 L1 P- axes <R- I- J- Q-> Set Tool Table
        // L10 - ref G5x + G92 - useful for probe (G38)
        // L11 - ref g59.3 only
        // Q: 1 - 8: 1: 135, 2: 45, 3: 315, 4: 225, 5: 180, 6: 90, 7: 0, 8: 270

        void saveOffset(string axis)
        {
            string s, axes;
            string xOffset = GrblWorkParameters.ConvertX(GrblWorkParameters.LatheMode, GrblParserState.LatheMode, selectedTool.X).ToInvariantString();

            switch (axis)
            {
            case "R":
                axes = "R{4}";
                break;

            case "All":
                axes = "X{1}Y{2}Z{3}R{4}";
                break;

            default:
                axes = (axis + "{" + (GrblInfo.AxisLetterToIndex(axis) + 1).ToString() + "}");
                break;
            }

            s = string.Format("G10L1P{0}" + axes, selectedTool.Code, xOffset, selectedTool.Y.ToInvariantString(), selectedTool.Z.ToInvariantString(), selectedTool.R.ToInvariantString());

            Comms.com.WriteCommand(s);
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
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);
            }
        }
Ejemplo n.º 19
0
        private void InitSystem()
        {
            initOK = true;

            // TODO: check if grbl is in a state that allows replies
            using (new UIUtils.WaitCursor())
            {
                GCodeSender.EnablePolling(false);
                GrblInfo.Get();
                GrblSettings.Get();
                GrblParserState.Get();
                GrblWorkParameters.Get();
                GCodeSender.EnablePolling(true);
            }

            model.Message = string.Empty;

            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.Facing);
                MainWindow.EnableView(true, ViewType.G76Threading);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.Turning);
                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);
            }

            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);
            }
        }
Ejemplo n.º 20
0
        private void OnDataContextPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (sender is GrblViewModel)
            {
                switch (e.PropertyName)
                {
                case nameof(GrblViewModel.GrblState):
                    if (initOK == false && ((GrblViewModel)sender).GrblState.State != GrblStates.Alarm)
                    {
                        InitSystem();
                    }
                    break;

                case nameof(GrblViewModel.IsSleepMode):
                    EnableUI(!((GrblViewModel)sender).IsSleepMode);
                    break;

                case nameof(GrblViewModel.IsJobRunning):
                    MainWindow.ui.JobRunning = ((GrblViewModel)sender).IsJobRunning;
                    if (GrblInfo.ManualToolChange)
                    {
                        GrblCommand.ToolChange = MainWindow.ui.JobRunning ? "T{0}M6" : "M61Q{0}";
                    }
                    break;

                case nameof(GrblViewModel.Tool):
                    if (GrblInfo.ManualToolChange && ((GrblViewModel)sender).Tool != GrblConstants.NO_TOOL)
                    {
                        GrblWorkParameters.RemoveNoTool();
                    }
                    break;

                case nameof(GrblViewModel.GrblReset):
                    if (((GrblViewModel)sender).GrblReset)
                    {
                        initOK = null;
                        Activate(true, ViewType.GRBL);
                    }
                    //         Comms.com.WriteCommand(GrblConstants.CMD_GETPARSERSTATE);
                    break;

                case nameof(GrblViewModel.ParserState):
                    if (((GrblViewModel)sender).GrblReset)
                    {
                        EnableUI(true);
                        //  ((GrblViewModel)sender).GrblReset = false;
                    }
                    break;

                case nameof(GrblViewModel.FileName):
                    string filename = ((GrblViewModel)sender).FileName;
                    MainWindow.ui.WindowTitle = filename;
                    if (filename.StartsWith("SDCard:"))
                    {
                        sdStream = true;
                        MainWindow.EnableView(false, ViewType.GCodeViewer);
                    }
                    else if (filename.StartsWith("Wizard:"))
                    {
                        if (MainWindow.IsViewVisible(ViewType.GCodeViewer))
                        {
                            MainWindow.EnableView(false, ViewType.GCodeViewer);
// For now - rendering of G76 must be implemented first                                MainWindow.GCodeViewer.Open(filename, GCodeSender.GCode.Tokens);
                        }
                    }
                    else if (!string.IsNullOrEmpty(filename) && MainWindow.IsViewVisible(ViewType.GCodeViewer))
                    {
                        MainWindow.EnableView(true, ViewType.GCodeViewer);
                        GCodeSender.EnablePolling(false);
                        MainWindow.GCodeViewer.Open(filename, GCode.File.Tokens);
                        GCodeSender.EnablePolling(true);
                    }
                    break;
                }
            }
        }
Ejemplo n.º 21
0
        private void InitSystem()
        {
            initOK = true;

            // TODO: check if grbl is in a state that allows replies
            using (new UIUtils.WaitCursor())
            {
                GCodeSender.EnablePolling(false);
                GrblInfo.Get();
                GrblSettings.Get();
                GrblParserState.Get();
                GrblWorkParameters.Get();
                GCodeSender.EnablePolling(true);
            }

            model.Message = "";

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

            GCodeSender.Config(MainWindow.UIViewModel.Profile.Config);

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

            if (GrblInfo.LatheModeEnabled)
            {
                MainWindow.EnableView(true, ViewType.Turning);
                MainWindow.EnableView(true, ViewType.Facing);
                MainWindow.EnableView(true, ViewType.G76Threading);
            }
            else
            {
                MainWindow.ShowView(false, ViewType.Turning);
                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);
            }

            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);
            }

            MainWindow.GCodePush += GCode.File.AddBlock;
        }
Ejemplo n.º 22
0
        public void Activate(bool activate, ViewType chgMode)
        {
            if (activate)
            {
                if (model.CoordinateSystems.Count == 0)
                {
                    //                   model.CoordinateSystems.Add(model.CoordinateSystem = new CoordinateSystem("Active", "0"));
                    foreach (var cs in GrblWorkParameters.CoordinateSystems)
                    {
                        if (cs.Id > 0 && cs.Id < 9)
                        {
                            model.CoordinateSystems.Add(new CoordinateSystem(cs.Code, "0"));
                        }

                        if (cs.Id == 9)
                        {
                            model.HasCoordinateSystem9 = true;
                        }
                    }
                    model.HasToolTable = GrblInfo.NumTools > 0;
                }

                if (GrblInfo.IsGrblHAL)
                {
                    Comms.com.WriteByte(GrblConstants.CMD_STATUS_REPORT_ALL);
                }

                if (!model.Grbl.IsGrblHAL && !AppConfig.Settings.Jog.KeyboardEnable)
                {
                    Jog.Visibility = Visibility.Collapsed;
                }

                if (GrblInfo.IsGrblHAL)
                {
                    GrblParserState.Get();
                    GrblWorkParameters.Get();
                }
                else
                {
                    GrblParserState.Get(true);
                }

                model.DistanceMode     = GrblParserState.DistanceMode;
                model.Tool             = model.Grbl.Tool == GrblConstants.NO_TOOL ? "0" : model.Grbl.Tool;
                model.CanProbe         = !model.Grbl.Signals.Value.HasFlag(Signals.Probe);
                model.HeightMapApplied = GCode.File.HeightMapApplied;
                int csid = GrblWorkParameters.GetCoordinateSystem(model.Grbl.WorkCoordinateSystem).Id;
                model.CoordinateSystem     = csid == 0 || csid >= 9 ? 1 : csid;
                model.ReferenceToolOffset &= model.CanReferenceToolOffset;

                if (model.Grbl.IsTloReferenceSet && !double.IsNaN(model.Grbl.TloReference))
                {
                    model.TloReference        = model.Grbl.TloReference;
                    model.ReferenceToolOffset = false;
                }

                Probing.Command = GrblInfo.ReportProbeResult ? "G38.3" : "G38.2";

                getView(tab.SelectedItem as TabItem)?.Activate();

                model.Grbl.PropertyChanged += Grbl_PropertyChanged;

                probeTriggered    = model.Grbl.Signals.Value.HasFlag(Signals.Probe);
                probeDisconnected = model.Grbl.Signals.Value.HasFlag(Signals.ProbeDisconnected);
                cycleStartSignal  = model.Grbl.Signals.Value.HasFlag(Signals.CycleStart);

                DisplayPosition(model.Grbl);
            }
            else
            {
                model.Grbl.PropertyChanged -= Grbl_PropertyChanged;

                if (!model.Grbl.IsGCLock)
                {
                    // If probing alarm active unlock
                    //if(model.Grbl.GrblState.State == GrblStates.Alarm && (model.Grbl.GrblState.Substate == 4 || model.Grbl.GrblState.Substate == 5))
                    //    model.WaitForResponse(GrblConstants.CMD_UNLOCK);
                    //else
                    if (model.Grbl.GrblError != 0)
                    {
                        model.WaitForResponse("");  // Clear error
                    }
                    model.WaitForResponse(model.DistanceMode == DistanceMode.Absolute ? "G90" : "G91");
                }
            }

            model.Message = string.Empty;
            model.Grbl.Poller.SetState(activate ? AppConfig.Settings.Base.PollInterval : 0);
        }
Ejemplo n.º 23
0
        private void OnDataContextPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (sender is GrblViewModel)
            {
                switch (e.PropertyName)
                {
                case nameof(GrblViewModel.GrblState):
                    if (!Controller.ResetPending)
                    {
                        if (initOK == false && (sender as GrblViewModel).GrblState.State != GrblStates.Alarm)
                        {
                            Dispatcher.BeginInvoke(new System.Action(() => InitSystem()), DispatcherPriority.ApplicationIdle);
                        }
                    }
                    break;

                case nameof(GrblViewModel.IsGCLock):
                    MainWindow.ui.JobRunning = (sender as GrblViewModel).IsJobRunning;
                    //             MainWindow.EnableView(!(sender as GrblViewModel).IsGCLock, ViewType.Probing);
                    break;

                case nameof(GrblViewModel.IsSleepMode):
                    EnableUI(!(sender as GrblViewModel).IsSleepMode);
                    break;

                case nameof(GrblViewModel.IsJobRunning):
                    MainWindow.ui.JobRunning = (sender as GrblViewModel).IsJobRunning;
                    if (GrblInfo.ManualToolChange)
                    {
                        GrblCommand.ToolChange = (sender as GrblViewModel).IsJobRunning ? "T{0}M6" : "M61Q{0}";
                    }
                    break;

                case nameof(GrblViewModel.IsToolChanging):
                    MainWindow.ui.JobRunning = (sender as GrblViewModel).IsToolChanging || (sender as GrblViewModel).IsJobRunning;
                    break;

                case nameof(GrblViewModel.Tool):
                    if (GrblInfo.ManualToolChange && (sender as GrblViewModel).Tool != GrblConstants.NO_TOOL)
                    {
                        GrblWorkParameters.RemoveNoTool();
                    }
                    break;

                case nameof(GrblViewModel.GrblReset):
                    if ((sender as GrblViewModel).IsReady)
                    {
                        if (!Controller.ResetPending && (sender as GrblViewModel).GrblReset)
                        {
                            initOK = null;
                            Dispatcher.BeginInvoke(new System.Action(() => Activate(true, ViewType.GRBL)), DispatcherPriority.ApplicationIdle);
                        }
                    }
                    break;

                case nameof(GrblViewModel.ParserState):
                    if (!Controller.ResetPending && (sender as GrblViewModel).GrblReset)
                    {
                        EnableUI(true);
                        (sender as GrblViewModel).GrblReset = false;
                    }
                    break;

                case nameof(GrblViewModel.FileName):
                    string filename = (sender as GrblViewModel).FileName;
                    MainWindow.ui.WindowTitle = filename;

                    if (string.IsNullOrEmpty(filename))
                    {
                        MainWindow.CloseFile();
                    }
                    else if ((sender as GrblViewModel).IsSDCardJob)
                    {
                        MainWindow.EnableView(false, ViewType.GCodeViewer);
                    }
                    else if (filename.StartsWith("Wizard:"))
                    {
                        if (MainWindow.IsViewVisible(ViewType.GCodeViewer))
                        {
                            MainWindow.EnableView(true, ViewType.GCodeViewer);
                            gcodeRenderer.Open(GCode.File.Tokens);
                        }
                    }
                    else if (!string.IsNullOrEmpty(filename) && AppConfig.Settings.GCodeViewer.IsEnabled)
                    {
                        MainWindow.GCodeViewer.Open(GCode.File.Tokens);
                        MainWindow.EnableView(true, ViewType.GCodeViewer);
                        GCodeSender.EnablePolling(false);
                        gcodeRenderer.Open(GCode.File.Tokens);
                        GCodeSender.EnablePolling(true);
                    }
                    break;
                }
            }
        }
        private void InitSystem()
        {
            initOK = true;

            // TODO: check if grbl is in a state that allows replies
            using (new UIUtils.WaitCursor())
            {
                GCodeSender.EnablePolling(false);
                GrblInfo.Get();
                GrblSettings.Get();
                GrblParserState.Get();
                GrblWorkParameters.Get();
                GCodeSender.EnablePolling(true);
            }

            workParametersControl.ToolChangeCommand = GrblInfo.ManualToolChange ? "T{0}M6" : "T{0}";

            GCodeSender.Config();

            if (GrblInfo.LatheModeEnabled)
            {
                DRO.EnableLatheMode();
                signalsControl.SetLatheMode();
                MainWindow.EnableView(true, ViewType.Turning);
                MainWindow.EnableView(true, ViewType.Facing);
                MainWindow.EnableView(true, ViewType.G76Threading);
            }
            else
            {
                DRO.SetNumAxes(GrblInfo.NumAxes);
                signalsControl.SetNumAxes(GrblInfo.NumAxes);
                MainWindow.ShowView(false, ViewType.Turning);
                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);
            }

            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);
            }

            MainWindow.GCodePush += UserUI_GCodePush;

            txtStatus.Text = "";
        }