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; }
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); }
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(); } } } } }
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); }
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); }
void btnReload_Click(object sender, RoutedEventArgs e) { using (new UIUtils.WaitCursor()) { GrblSettings.Load(); } }