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); }
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); }
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); }
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; }
void btnReload_Click(object sender, RoutedEventArgs e) { using (new UIUtils.WaitCursor()) { GrblSettings.Get(); } }
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); } }
public bool LoadFile(string filename) { bool ok = false; List <string> lines = new List <string>(); FileInfo file = new FileInfo(filename); StreamReader sr = file.OpenText(); string block = sr.ReadLine(); while (block != null) { try { ok |= block.StartsWith("$"); lines.Add(block.Trim()); block = sr.ReadLine(); } catch (Exception e) { if ((ok = MessageBox.Show("Bummer...\r\rContinue loading?", e.Message, MessageBoxButton.YesNo) == MessageBoxResult.Yes)) { block = sr.ReadLine(); } else { block = null; } } } sr.Close(); if (ok) { bool?res = null; CancellationToken cancellationToken = new CancellationToken(); Comms.com.PurgeQueue(); foreach (var cmd in lines) { if (cmd.StartsWith(";")) { continue; } 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("Setting {0} returned {1}, continue?", cmd, retval), "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No) { break; } } else if (res == false && MessageBox.Show(string.Format("Timed out while setting {0} , continue?", cmd), "ioSender", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No) { break; } } using (new UIUtils.WaitCursor()) { GrblSettings.Get(); } } else { MessageBox.Show("The file does not contain any settings.", "ioSender"); } model.Message = string.Empty; return(ok); }
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); } }
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 = ""; }