public void Activate(bool activate, ViewType chgMode)
 {
     if (activate)
     {
         foreach (var control in model.ConfigControls)         // TODO: use callback!
         {
             if (control is JogConfigControl)
             {
                 if (GrblSettings.GetString(GrblSetting.JogStepSpeed) != null)
                 {
                     control.Visibility = Visibility.Hidden;
                 }
                 else
                 {
                     (control as JogConfigControl).IsGrbl = !GrblInfo.IsGrblHAL;
                 }
             }
             else if (control is ICameraConfig && model.Camera != null && !model.Camera.HasCamera)
             {
                 control.Visibility = Visibility.Collapsed;
             }
         }
     }
     grblmodel.Message = activate ? "A restart is required after changing settings!" : string.Empty;
 }
Esempio n. 2
0
 public void Activate(bool activate, ViewType chgMode)
 {
     if (activate)
     {
         foreach (var control in model.ConfigControls)         // TODO: use callback!
         {
             if (control is JogConfigControl)
             {
                 if (GrblSettings.GetString(grblHALSetting.JogStepSpeed) != null)
                 {
                     control.Visibility = Visibility.Collapsed;
                 }
                 else
                 {
                     (control as JogConfigControl).IsGrbl = !GrblInfo.IsGrblHAL;
                 }
             }
             else if (control is ICameraConfig && model.Camera != null && !model.Camera.HasCamera)
             {
                 control.Visibility = Visibility.Collapsed;
             }
         }
     }
     grblmodel.Message = activate ? (string)FindResource("RestartMessage") : string.Empty;
 }
Esempio n. 3
0
        public void ShowPosition()
        {
            GrblViewModel model = (GrblViewModel)DataContext;

            Machine.ToolPosition = null;

            positionPoints.Clear();

            if (Machine.Limits.X == 0d)
            {
                Machine.SetLimits(GrblSettings.GetDouble(GrblSetting.AxisSetting_XMaxTravel),
                                  GrblSettings.GetDouble(GrblSetting.AxisSetting_YMaxTravel),
                                  GrblSettings.GetDouble(GrblSetting.AxisSetting_ZMaxTravel));
            }

            positionPoints.Add(new Point3D(Math.Min(model.Position.X, model.ProgramLimits.MinX) - 5d, model.Position.Y, model.Position.Z));
            positionPoints.Add(new Point3D(Machine.Limits.X, model.Position.Y, model.Position.Z));

            positionPoints.Add(new Point3D(model.Position.X, Math.Min(model.Position.Y, model.ProgramLimits.MinY) - 5d, model.Position.Z));
            positionPoints.Add(new Point3D(model.Position.X, Machine.Limits.Y, model.Position.Z));

            positionPoints.Add(new Point3D(model.Position.X, model.Position.Y, Math.Min(model.Position.Z, model.ProgramLimits.MinZ) - 5d));
            positionPoints.Add(new Point3D(model.Position.X, model.Position.Y, Machine.Limits.Z));

            Machine.ToolPosition = positionPoints;
            var orgpos = Machine.StartPosition;

            Machine.SetStartPosition(model.Position.X, model.Position.Y, model.Position.Z);

            if (Machine.RapidLines != null && Machine.RapidLines.Count > 0 && Machine.RapidLines[0].Equals(orgpos))
            {
                Machine.RapidLines.RemoveAt(0);
                Machine.RapidLines.Insert(0, Machine.StartPosition);
            }
        }
Esempio n. 4
0
 void btnSave_Click(object sender, RoutedEventArgs e)
 {
     if (curSetting != null)
     {
         curSetting.Assign();
     }
     GrblSettings.Save();
 }
Esempio n. 5
0
 private void AxisEnabled_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (AxisEnabled.Value.ToString().Length == 1)
     {
         Comms.com.WriteString(string.Format("M122{0}S1\r", AxisEnabled.Value.ToString()));
         SGValue = GrblSettings.GetInteger(grblHALSetting.StallGuardBase + GrblInfo.AxisLetterToIndex(AxisEnabled.Value.ToString()));
     }
 }
Esempio n. 6
0
 public ActiveStatusViewModel()
 {
     _grblSettings          = ViewModelLocator.GrblSettings;
     _statusTimer           = new Timer();
     _statusTimer.Interval  = 1000;
     _statusTimer.Elapsed  += _statusTimer_Elapsed;
     _statusTimer.AutoReset = false;
     _statusTimer.Start();
     RaiseAllProperties();
 }
Esempio n. 7
0
        void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (curSetting != null)
            {
                curSetting.Assign();
            }

            model.Message = string.Empty;

            GrblSettings.Save();
        }
Esempio n. 8
0
        // Configure to match Grbl settings (if loaded)
        public bool Config(Config config)
        {
            bool useFirmwareJog = false;

            if (GrblSettings.Loaded)
            {
                double val;
                if ((useFirmwareJog = !(val = GrblSettings.GetDouble(GrblSetting.JogStepDistance)).Equals(double.NaN)))
                {
                    jogDistance[(int)JogMode.Step] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogSlowDistance)).Equals(double.NaN))
                {
                    jogDistance[(int)JogMode.Slow] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogFastDistance)).Equals(double.NaN))
                {
                    jogDistance[(int)JogMode.Fast] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogStepSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Step] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogSlowSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Slow] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogFastSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Fast] = val;
                }

                model.IsMetric = GrblSettings.GetString(GrblSetting.ReportInches) != "1";
            }

            if (!useFirmwareJog)
            {
                jogDistance[(int)JogMode.Step] = config.Jog.StepDistance;
                jogDistance[(int)JogMode.Slow] = config.Jog.SlowDistance;
                jogDistance[(int)JogMode.Fast] = config.Jog.SlowDistance;
                jogSpeed[(int)JogMode.Step]    = config.Jog.StepFeedrate;
                jogSpeed[(int)JogMode.Slow]    = config.Jog.SlowFeedrate;
                jogSpeed[(int)JogMode.Fast]    = config.Jog.FastFeedrate;
            }

            GCodeParser.IgnoreM6 = config.IgnoreM6;
            GCodeParser.IgnoreM7 = config.IgnoreM7;
            GCodeParser.IgnoreM8 = config.IgnoreM8;

            useBuffering = config.UseBuffering && GrblSettings.IsGrblHAL;

            return(GrblSettings.Loaded);
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            System.Threading.Thread.Sleep(50);
            Comms.com.PurgeQueue();

            using (new UIUtils.WaitCursor())
            {
                GrblInfo.Get();
                GrblSettings.Get();
            }

            configView.Activate(true, ViewType.Startup);
        }
 public void Activate(bool activate, ViewType chgMode)
 {
     foreach (var control in model.ConfigControls) // TODO: use callback!
     {
         if (control is JogConfigControl && GrblSettings.GetString(GrblSetting.JogStepSpeed) != null)
         {
             control.Visibility = Visibility.Collapsed;
         }
         else if (control is ICameraConfig && model.Camera != null && !model.Camera.HasCamera)
         {
             control.Visibility = Visibility.Collapsed;
         }
     }
 }
        public KeypressHandler(GrblViewModel model)
        {
            grbl = model;

            bool useFirmwareJog = false;

            if (GrblSettings.IsLoaded)
            {
                double val;
                if ((useFirmwareJog = !(val = GrblSettings.GetDouble(GrblSetting.JogStepDistance)).Equals(double.NaN)))
                {
                    jogDistance[(int)JogMode.Step] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogSlowDistance)).Equals(double.NaN))
                {
                    jogDistance[(int)JogMode.Slow] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogFastDistance)).Equals(double.NaN))
                {
                    jogDistance[(int)JogMode.Fast] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogStepSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Step] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogSlowSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Slow] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogFastSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Fast] = val;
                }

                model.IsMetric = GrblSettings.GetString(GrblSetting.ReportInches) != "1";
            }

            if (!useFirmwareJog)
            {
                model.JogStep = jogDistance[(int)JogMode.Step] = AppConfig.Settings.Jog.StepDistance;
                jogDistance[(int)JogMode.Slow] = AppConfig.Settings.Jog.SlowDistance;
                jogDistance[(int)JogMode.Fast] = AppConfig.Settings.Jog.SlowDistance;
                jogSpeed[(int)JogMode.Step]    = AppConfig.Settings.Jog.StepFeedrate;
                jogSpeed[(int)JogMode.Slow]    = AppConfig.Settings.Jog.SlowFeedrate;
                jogSpeed[(int)JogMode.Fast]    = AppConfig.Settings.Jog.FastFeedrate;
            }

            fullJog = AppConfig.Settings.Jog.KeyboardEnable || GrblSettings.IsGrblHAL;
        }
Esempio n. 12
0
        private bool SetSetting(KeyValuePair <int, string> setting)
        {
            bool?res = null;
            CancellationToken cancellationToken = new CancellationToken();
            var scmd = string.Format("${0}={1}", setting.Key, setting.Value);

            retval = string.Empty;

            new Thread(() =>
            {
                res = WaitFor.AckResponse <string>(
                    cancellationToken,
                    response => Process(response),
                    a => model.OnResponseReceived += a,
                    a => model.OnResponseReceived -= a,
                    400, () => Comms.com.WriteCommand(scmd));
            }).Start();

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

            if (retval != string.Empty)
            {
                if (retval.StartsWith("error:"))
                {
                    var msg = GrblErrors.GetMessage(retval.Substring(6));
                    if (msg != retval)
                    {
                        retval += " - \"" + msg + "\"";
                    }
                }

                var details = GrblSettings.Get((GrblSetting)setting.Key);

                if (MessageBox.Show(string.Format((string)FindResource("SettingsError"), scmd, retval), "ioSender" + (details == null ? "" : " - " + details.Name), MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No)
                {
                    return(false);
                }
            }
            else if (res == false && MessageBox.Show(string.Format((string)FindResource("SettingsTimeout"), scmd), "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 13
0
        public UserUI()
        {
            string PortParams = "";

            InitializeComponent();

            try
            {
                XmlDocument config = new XmlDocument();

                config.Load(Application.StartupPath + "\\App.config");

                foreach (XmlNode N in config.SelectNodes("Config/*"))
                {
                    switch (N.Name)
                    {
                    case "PortParams":
                        PortParams = N.InnerText;
                        break;
                    }
                }
            }
            catch
            {
                MessageBox.Show("Config file not found or invalid.", this.Text);
                System.Environment.Exit(1);
            }

#if DEBUG
            PortParams = "com29:115200,N,8,1,P";
#endif

            new SerialComms(PortParams, Comms.ResetMode.None);

            if (!Comms.com.IsOpen)
            {
                this.com = null;
                MessageBox.Show("Unable to open serial port!", this.Text);
                System.Environment.Exit(2);
            }

            GrblLanguage.language = "en_US";

            GrblInfo.Get();
            GrblSettings.Load();

            this.Text += ", Grbl version " + GrblInfo.Version;
        }
Esempio n. 14
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            System.Threading.Thread.Sleep(50);
            Comms.com.PurgeQueue();

            using (new UIUtils.WaitCursor())
            {
                GrblInfo.Get();
                GrblSettings.Load();
            }

            halsettings.IsEnabled = grblsettings.IsEnabled = GrblInfo.IsGrblHAL && GrblInfo.Build >= 20210819;
            grblalarms.IsEnabled  = grblerrors.IsEnabled = GrblInfo.IsGrblHAL && GrblInfo.Build >= 20210823;

            configView.Activate(true, ViewType.Startup);
        }
Esempio n. 15
0
        private void updateConfig()
        {
            grbl.JogStep = jogDistance[(int)JogMode.Step] = AppConfig.Settings.Jog.StepDistance;
            jogDistance[(int)JogMode.Slow] = AppConfig.Settings.Jog.SlowDistance;
            jogDistance[(int)JogMode.Fast] = AppConfig.Settings.Jog.SlowDistance;
            jogSpeed[(int)JogMode.Step]    = AppConfig.Settings.Jog.StepFeedrate;
            jogSpeed[(int)JogMode.Slow]    = AppConfig.Settings.Jog.SlowFeedrate;
            jogSpeed[(int)JogMode.Fast]    = AppConfig.Settings.Jog.FastFeedrate;

            softLimits = GrblSettings.GetInteger(GrblSetting.SoftLimitsEnable) == 1;

            if (!GrblInfo.IsGrblHAL)
            {
                fullJog = AppConfig.Settings.Jog.KeyboardEnable;
            }
        }
        public void ShowPosition()
        {
            GrblViewModel model = (GrblViewModel)DataContext;

            foreach (var path in position)
            {
                viewport.Children.Remove(path);
            }

            position.Clear();

            double maxX = GrblSettings.GetDouble(GrblSetting.AxisSetting_XMaxTravel);
            double maxY = GrblSettings.GetDouble(GrblSetting.AxisSetting_YMaxTravel);
            double maxZ = GrblSettings.GetDouble(GrblSetting.AxisSetting_ZMaxTravel);

            var positionX = new LinesVisual3D();

            positionX.Color     = Colors.Green;
            positionX.Thickness = 1;
            positionX.Points.Add(new Point3D(model.ProgramLimits.MinX - 5d, model.Position.Y, model.Position.Z));
            positionX.Points.Add(new Point3D(maxX, model.Position.Y, model.Position.Z));
            position.Add(positionX);

            var positionY = new LinesVisual3D();

            positionY.Color     = Colors.Green;
            positionY.Thickness = 1;
            positionY.Points.Add(new Point3D(model.Position.X, model.ProgramLimits.MinY - 5d, model.Position.Z));
            positionY.Points.Add(new Point3D(model.Position.X, maxY, model.Position.Z));
            position.Add(positionY);

            var positionZ = new LinesVisual3D();

            positionZ.Color     = Colors.Green;
            positionZ.Thickness = 1;
            positionZ.Points.Add(new Point3D(model.Position.X, model.Position.Y, model.ProgramLimits.MinZ - 5d));
            positionZ.Points.Add(new Point3D(model.Position.X, model.Position.Y, maxZ));
            position.Add(positionZ);

            foreach (var path in position)
            {
                viewport.Children.Add(path);
            }
        }
Esempio n. 17
0
        public KeypressHandler(GrblViewModel model)
        {
            grbl = model;

            bool useFirmwareJog = false;

            if (GrblSettings.IsLoaded)
            {
                double val;
                if ((useFirmwareJog = !(val = GrblSettings.GetDouble(GrblSetting.JogStepDistance)).Equals(double.NaN)))
                {
                    jogDistance[(int)JogMode.Step] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogSlowDistance)).Equals(double.NaN))
                {
                    jogDistance[(int)JogMode.Slow] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogFastDistance)).Equals(double.NaN))
                {
                    jogDistance[(int)JogMode.Fast] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogStepSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Step] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogSlowSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Slow] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogFastSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Fast] = val;
                }

                fullJog        = GrblSettings.IsGrblHAL;
                model.IsMetric = GrblSettings.GetString(GrblSetting.ReportInches) != "1";
            }

            if (!useFirmwareJog)
            {
                AppConfig.Settings.Jog.PropertyChanged += Jog_PropertyChanged;
                updateConfig();
            }
        }
        public void Activate(bool activate, ViewType chgMode)
        {
            Comms.com.WriteString(string.Format("M122S{0}H{1}\r", activate ? 1 : 0, SFiltEnabled == true ? 1 : 0));

            if (activate)
            {
                DataContext = model;
                model.OnResponseReceived += ProcessSGValue;
                model.PropertyChanged    += OnDataContextPropertyChanged;
                SGValue = GrblSettings.GetInteger(GrblSetting.StallGuardBase + GrblInfo.AxisLetterToIndex(AxisEnabled.Value.ToString()));
            }
            else
            {
                model.OnResponseReceived -= ProcessSGValue;
                model.PropertyChanged    -= OnDataContextPropertyChanged;
                DataContext = null;
            }
            model.Poller.SetState(activate ? AppConfig.Settings.Base.PollInterval : 0);
        }
Esempio n. 19
0
        public void Activate(bool activate, ViewType chgMode)
        {
            if (model != null)
            {
                btnSave.IsEnabled = !model.IsCheckMode;
                model.Message     = string.Empty;

                if (activate)
                {
                    using (new UIUtils.WaitCursor())
                    {
                        GrblSettings.Load();
                    }

                    if (treeView.SelectedItem != null && treeView.SelectedItem is GrblSettingDetails)
                    {
                        ShowSetting(treeView.SelectedItem as GrblSettingDetails, false);
                    }
                    else if (dgrSettings.SelectedItem != null)
                    {
                        ShowSetting(dgrSettings.SelectedItem as GrblSettingDetails, false);
                    }
                }
                else
                {
                    if (curSetting != null)
                    {
                        curSetting.Assign();
                    }

                    if (GrblSettings.HasChanges())
                    {
                        if (MessageBox.Show((string)FindResource("SaveSettings"), "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
                        {
                            GrblSettings.Save();
                        }
                    }
                }
            }
        }
Esempio n. 20
0
        // Configure to match Grbl settings (if loaded)
        public bool Config()
        {
            if (GrblSettings.Loaded)
            {
                double val;
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogStepDistance)).Equals(double.NaN))
                {
                    jogDistance[(int)JogMode.Step] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogSlowDistance)).Equals(double.NaN))
                {
                    jogDistance[(int)JogMode.Slow] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogFastDistance)).Equals(double.NaN))
                {
                    jogDistance[(int)JogMode.Fast] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogStepSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Step] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogSlowSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Slow] = val;
                }
                if (!(val = GrblSettings.GetDouble(GrblSetting.JogFastSpeed)).Equals(double.NaN))
                {
                    jogSpeed[(int)JogMode.Fast] = val;
                }

                if (GrblSettings.GetString(GrblSetting.ReportInches) == "1")
                {
                    model.Unit   = "in";
                    model.Format = GrblConstants.FORMAT_IMPERIAL;
                }
            }

            return(GrblSettings.Loaded);
        }
Esempio n. 21
0
        public bool Update()
        {
            if (GrblSettings.IsLoaded)
            {
                XMaxFeedRate  = GrblSettings.GetDouble(GrblSetting.AxisSetting_XMaxRate);
                XAcceleration = GrblSettings.GetDouble(GrblSetting.AxisSetting_XAcceleration);
                ZMaxFeedRate  = GrblSettings.GetDouble(GrblSetting.AxisSetting_ZMaxRate);
                ZAcceleration = GrblSettings.GetDouble(GrblSetting.AxisSetting_ZAcceleration);
                RpmMin        = GrblSettings.GetDouble(GrblSetting.RpmMin);
                RpmMax        = GrblSettings.GetDouble(GrblSetting.RpmMax);

                GrblParserState.Get();

                if (!xmodelock)
                {
                    xmode = GrblParserState.LatheMode;
                }

                SetLimits();
            }

            return(GrblSettings.IsLoaded);
        }
Esempio n. 22
0
        public void Activate(bool activate, ViewType chgMode)
        {
            Comms.com.WriteString(string.Format("M122S{0}H{1}\r", activate ? 1 : 0, SFiltEnabled == true ? 1 : 0));

            if (activate)
            {
                DataContext = model;
                model.OnResponseReceived += ProcessSGValue;
                model.PropertyChanged    += OnDataContextPropertyChanged;
                var sgdetails = GrblSettings.Get(grblHALSetting.StallGuardBase + GrblInfo.AxisLetterToIndex(AxisEnabled.Value.ToString()));
                SGValue    = int.Parse(sgdetails.Value);
                SGValueMin = (int)sgdetails.Min;
                SGValueMax = (int)sgdetails.Max;
                grbl_reset = false;
            }
            else
            {
                model.OnResponseReceived -= ProcessSGValue;
                model.PropertyChanged    -= OnDataContextPropertyChanged;
                DataContext = null;
            }
            model.Poller.SetState(activate ? AppConfig.Settings.Base.PollInterval : 0);
        }
Esempio n. 23
0
        public bool Update()
        {
            if (GrblSettings.IsLoaded)
            {
                XMaxFeedRate  = GrblSettings.GetDouble(GrblSetting.MaxFeedRateBase);
                XAcceleration = GrblSettings.GetDouble(GrblSetting.AccelerationBase);
                ZMaxFeedRate  = GrblSettings.GetDouble(GrblSetting.MaxFeedRateBase + GrblConstants.Z_AXIS);
                ZAcceleration = GrblSettings.GetDouble(GrblSetting.AccelerationBase + GrblConstants.Z_AXIS);
                RpmMin        = GrblSettings.GetDouble(GrblSetting.RpmMin);
                RpmMax        = GrblSettings.GetDouble(GrblSetting.RpmMax);

                GrblParserState.Get();

                if (!xmodelock)
                {
                    xmode = GrblParserState.LatheMode;
                }

                SetLimits();
            }

            return(GrblSettings.IsLoaded);
        }
Esempio n. 24
0
 public Program()
 {
     gc = new TcpGrblClient();
     gs = new GrblSettings();
     if (gc.Start("192.168.1.15", 8887))
     {
         running = true;
         new Thread(new ThreadStart(ReadMain)).Start();
         while (gc.IsRunning)
         {
             if (gc.IsPaused)
             {
                 Console.WriteLine("PAUSED");
             }
             if (gc.Responses.Count > 0)
             {
                 GrblResponse r = gc.Responses.Pop();
                 gs.Parse(r);
                 Console.WriteLine(r.Content);
             }
             Thread.Sleep(10);
         }
     }
 }
Esempio n. 25
0
 private void clbButton_Click(object sender, System.EventArgs e)
 {
     GrblSettings.CopyToClipboard();
 }
Esempio n. 26
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);
        }
Esempio n. 27
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;
        }
Esempio n. 28
0
 void btnBackup_Click(object sender, RoutedEventArgs e)
 {
     GrblSettings.Backup(string.Format("{0}settings.txt", CNC.Core.Resources.Path));
 }
Esempio n. 29
0
 void btnReload_Click(object sender, RoutedEventArgs e)
 {
     using (new UIUtils.WaitCursor()) {
         GrblSettings.Get();
     }
 }
Esempio n. 30
0
        public bool LoadFile(string filename)
        {
            int                      pos, id;
            List <string>            lines    = new List <string>();
            List <int>               dep      = new List <int>();
            Dictionary <int, string> settings = new Dictionary <int, string>();
            FileInfo                 file     = new FileInfo(filename);
            StreamReader             sr       = file.OpenText();

            string block = sr.ReadLine();

            while (block != null)
            {
                block = block.Trim();
                try
                {
                    if (lines.Count == 0 && model.IsGrblHAL && block == "%")
                    {
                        lines.Add(block);
                    }
                    else if (block.StartsWith("$") && (pos = block.IndexOf('=')) > 1)
                    {
                        if (int.TryParse(block.Substring(1, pos - 1), out id))
                        {
                            settings.Add(id, block.Substring(pos + 1));
                        }
                        else
                        {
                            lines.Add(block);
                        }
                    }

                    block = sr.ReadLine();
                }
                catch (Exception e)
                {
                    if (MessageBox.Show(((string)FindResource("SettingsFail")).Replace("\\n", "\r\r"), e.Message, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                    {
                        block = sr.ReadLine();
                    }
                    else
                    {
                        block = null;
                        settings.Clear();
                        lines.Clear();
                    }
                }
            }

            sr.Close();

            if (settings.Count == 0)
            {
                MessageBox.Show((string)FindResource("SettingsInvalid"));
            }
            else
            {
                bool?res = null;
                CancellationToken cancellationToken = new CancellationToken();

                // List of settings that have other dependent settings and have to be set before them
                dep.Add((int)GrblSetting.HomingEnable);

                foreach (var cmd in lines)
                {
                    res    = null;
                    retval = string.Empty;

                    new Thread(() =>
                    {
                        res = WaitFor.AckResponse <string>(
                            cancellationToken,
                            response => Process(response),
                            a => model.OnResponseReceived += a,
                            a => model.OnResponseReceived -= a,
                            400, () => Comms.com.WriteCommand(cmd));
                    }).Start();

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

                    if (retval != string.Empty)
                    {
                        if (MessageBox.Show(string.Format((string)FindResource("SettingsError"), cmd, retval), "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No)
                        {
                            break;
                        }
                    }
                    else if (res == false && MessageBox.Show(string.Format((string)FindResource("SettingsTimeout"), cmd), "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No)
                    {
                        break;
                    }
                }

                foreach (var d in dep)
                {
                    if (settings.ContainsKey(d))
                    {
                        if (!SetSetting(new KeyValuePair <int, string>(d, settings[d])))
                        {
                            settings.Clear();
                            break;
                        }
                    }
                }

                foreach (var setting in settings)
                {
                    if (!dep.Contains(setting.Key))
                    {
                        if (!SetSetting(setting))
                        {
                            break;
                        }
                    }
                }

                if (lines[0] == "%")
                {
                    Comms.com.WriteCommand("%");
                }

                using (new UIUtils.WaitCursor())
                {
                    GrblSettings.Load();
                }
            }

            model.Message = string.Empty;

            return(settings.Count > 0);
        }