private void cbxTool_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count == 1 && ((ComboBox)sender).IsDropDownOpen) { Grbl.MDICommand(DataContext, string.Format(ToolChangeCommand, ((Tool)e.AddedItems[0]).Code)); } }
void btn_Click(object sender, RoutedEventArgs e) { switch ((StatusButton)((Control)sender).Tag) { case StatusButton.Reset: Grbl.Reset(); break; case StatusButton.Unlock: (DataContext as GrblViewModel).ExecuteCommand(GrblConstants.CMD_UNLOCK); break; case StatusButton.Home: // ((Control)sender).Background = Brushes.LightSkyBlue; (DataContext as GrblViewModel).ExecuteCommand(GrblConstants.CMD_HOMING); break; case StatusButton.Check: GrblStates state = (DataContext as GrblViewModel).GrblState.State; if(state == GrblStates.Check && (sender as CheckBox).IsChecked == false) Grbl.Reset(); else if (state == GrblStates.Idle && (sender as CheckBox).IsChecked == true) (DataContext as GrblViewModel).ExecuteCommand(GrblConstants.CMD_CHECK); break; } }
private void ResponseReceived(string response) { if (Grbl.ResponseLogVerbose) { Grbl.ResponseLog.Add("PM:" + response); } if (response == "ok") { step++; if (step < _program.Count) { Grbl.ExecuteCommand(_program[step]); } } if (step == _program.Count || response != "ok") { IsSuccess = step == _program.Count && response == "ok"; if (!IsSuccess) { End("Probing cancelled/failed"); } IsCompleted = true; } }
public bool WaitForResponse(string command) { bool?res = null; if (Grbl.ResponseLogVerbose) { Grbl.ResponseLog.Add(command); } new Thread(() => { res = WaitFor.AckResponse <string>( cancellationToken, null, a => Grbl.OnResponseReceived += a, a => Grbl.OnResponseReceived -= a, 5000, () => Grbl.ExecuteCommand(command)); }).Start(); while (res == null) { EventUtils.DoEvents(); } return(res == true); }
private void cbxOffset_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count == 1 && ((ComboBox)sender).IsDropDownOpen) { Grbl.MDICommand(DataContext, ((CoordinateSystem)e.AddedItems[0]).Code); } }
private void ExecuteProgram(bool go) { if (_program.Count > 0) { step = 0; _isComplete = _isSuccess = isCancelled = false; _positions.Clear(); _machine.Clear(); Comms.com.PurgeQueue(); if (!isRunning) { isRunning = true; Grbl.OnCommandResponseReceived += ResponseReceived; Grbl.PropertyChanged += Grbl_PropertyChanged; } Grbl.IsJobRunning = true; if (Message == string.Empty) { Message = "Probing..."; } Grbl.ExecuteCommand(_program[step]); } }
void btnSend_Click(object sender, RoutedEventArgs e) { if (txtMDI.Text != "") { Grbl.MDICommand(DataContext, txtMDI.Text); } }
void AxisPositionChanged(string axis, double position) { if (axis == "ALL") { string s = "G90G10L20P0"; for (int i = 0; i < GrblInfo.NumAxes; i++) { s += GrblInfo.AxisIndexToLetter(i) + "{0}"; } Grbl.MDICommand(DataContext, string.Format(s, position.ToInvariantString("F3"))); } else { Grbl.MDICommand(DataContext, string.Format("G10L20P0{0}{1}", axis, position.ToInvariantString("F3"))); } }
private void rbSpindle_Click(object sender, RoutedEventArgs e) { var p = (GrblViewModel)DataContext; if (p.SpindleState.Value != SpindleState.Off) { _rpm = cvRPM.Value; } if (hold) { Grbl.MDICommand(DataContext, ((char)GrblConstants.CMD_SPINDLE_OVR_STOP).ToString()); } else { Grbl.MDICommand(DataContext, string.Format((string)((RadioButton)sender).Tag, "S" + cvRPM.Value.ToInvariantString())); } }
void btn_Click(object sender, RoutedEventArgs e) { switch ((StatusButton)((Control)sender).Tag) { case StatusButton.Reset: var model = (DataContext as GrblViewModel); if (model.GrblState.State == GrblStates.Alarm && model.GrblState.Substate == 10 && model.Signals.Value.HasFlag(Signals.EStop)) { MessageBox.Show((string)FindResource("ClearEStop"), "ioSender", MessageBoxButton.OK, MessageBoxImage.Exclamation); } else { Grbl.Reset(); } break; case StatusButton.Unlock: (DataContext as GrblViewModel).ExecuteCommand(GrblConstants.CMD_UNLOCK); break; case StatusButton.Home: // ((Control)sender).Background = Brushes.LightSkyBlue; (DataContext as GrblViewModel).ExecuteCommand(GrblConstants.CMD_HOMING); break; case StatusButton.Check: GrblStates state = (DataContext as GrblViewModel).GrblState.State; if (state == GrblStates.Check && (sender as CheckBox).IsChecked == false) { Grbl.Reset(); } else if (state == GrblStates.Idle && (sender as CheckBox).IsChecked == true) { (DataContext as GrblViewModel).ExecuteCommand(GrblConstants.CMD_CHECK); } break; } }
void Camera_MoveOffset(CameraMoveMode Mode, double XOffset, double YOffset) { Comms.com.WriteString("G91G0\r"); // Enter relative G0 mode - set scale to 1.0? switch (Mode) { case CameraMoveMode.XAxisFirst: Comms.com.WriteString(string.Format("X{0}\r", XOffset.ToInvariantString("F3"))); Comms.com.WriteString(string.Format("Y{0}\r", YOffset.ToInvariantString("F3"))); break; case CameraMoveMode.YAxisFirst: Comms.com.WriteString(string.Format("Y{0}\r", YOffset.ToInvariantString("F3"))); Comms.com.WriteString(string.Format("X{0}\r", XOffset.ToInvariantString("F3"))); break; case CameraMoveMode.BothAxes: Grbl.MDICommand(DataContext, string.Format("X{0}Y{1}", XOffset.ToInvariantString("F3"), YOffset.ToInvariantString("F3"))); break; } Comms.com.WriteString("G90\r"); // reset to previous or G80 to cancel motion mode? }
public bool GotoMachinePosition(Position pos, AxisFlags axisflags) { bool?res = null; bool wait = true; string command = "G53G0" + pos.ToString(axisflags); Comms.com.PurgeQueue(); new Thread(() => { res = WaitFor.AckResponse <string>( cancellationToken, null, a => Grbl.OnResponseReceived += a, a => Grbl.OnResponseReceived -= a, 100, () => Grbl.ExecuteCommand(command)); }).Start(); while (res == null) { EventUtils.DoEvents(); } if (res == true) { while (wait && !isCancelled) { res = null; new Thread(() => { res = WaitFor.SingleEvent <string>( cancellationToken, null, a => Grbl.OnRealtimeStatusProcessed += a, a => Grbl.OnRealtimeStatusProcessed -= a, 200, () => Comms.com.WriteByte(GrblLegacy.ConvertRTCommand(GrblConstants.CMD_STATUS_REPORT))); }).Start(); while (res == null) { EventUtils.DoEvents(); } wait = res != true; int i = 0, axes = (int)axisflags; while (axes != 0 && !wait) { if ((axes & 0x01) != 0) { wait = Math.Abs(pos.Values[i] - Grbl.MachinePosition.Values[i]) >= 0.003d; // use step resolution plus some? } i++; axes >>= 1; } if (wait) { Thread.Sleep(200); // needed? } } } return(isCancelled ? false : !wait); }
public bool GotoMachinePosition(Position pos, AxisFlags axisflags) { bool? res = null; bool wait = true, running = false; double delta, delta_max = 0d; string command = "G53" + RapidCommand + pos.ToString(axisflags); Comms.com.PurgeQueue(); Grbl.Poller.SetState(0); new Thread(() => { res = WaitFor.AckResponse <string>( cancellationToken, null, a => Grbl.OnResponseReceived += a, a => Grbl.OnResponseReceived -= a, 1000, () => Grbl.ExecuteCommand(command)); }).Start(); while (res == null) { EventUtils.DoEvents(); } if (res == true) { while (wait && !isCancelled) { res = null; new Thread(() => { res = WaitFor.SingleEvent <string>( cancellationToken, null, a => Grbl.OnRealtimeStatusProcessed += a, a => Grbl.OnRealtimeStatusProcessed -= a, 400, () => Comms.com.WriteByte(GrblLegacy.ConvertRTCommand(GrblConstants.CMD_STATUS_REPORT))); }).Start(); while (res == null) { EventUtils.DoEvents(); } wait = res != true; running |= Grbl.GrblState.State == GrblStates.Run; int i = 0, axes = (int)axisflags; while (axes != 0 && !wait) { if ((axes & 0x01) != 0) { delta = Math.Abs(pos.Values[i] - Grbl.MachinePosition.Values[i]); wait = delta > Math.Max(0.003d, GrblInfo.TravelResolution.Values[i] * 2d); delta_max = Math.Max(delta, delta_max); if (wait && Grbl.GrblState.State == GrblStates.Idle && (running || delta_max < 0.01d)) { wait = false; isCancelled = true; } } i++; axes >>= 1; } if (wait) { Thread.Sleep(AppConfig.Settings.Base.PollInterval); // needed? } } } Grbl.Poller.SetState(AppConfig.Settings.Base.PollInterval); return(isCancelled ? false : !wait); }
private void chkBox_Click(object sender, System.Windows.RoutedEventArgs e) { Grbl.MDICommand(DataContext, (string)((CheckBox)sender).Tag); }
void override_CommandGenerated(string command) { Grbl.MDICommand(DataContext, command); }
public bool Init() { bool?res = null; Message = String.Empty; Grbl.Poller.SetState(0); // Disable status polling during probing // Clear error status if set if (Grbl.GrblError != 0) { new Thread(() => { res = WaitFor.AckResponse <string>( cancellationToken, null, a => Grbl.OnResponseReceived += a, a => Grbl.OnResponseReceived -= a, 1000, () => Grbl.ExecuteCommand("")); }).Start(); while (res == null) { EventUtils.DoEvents(); } res = null; } // Get a status report in order to establish current machine position new Thread(() => { res = WaitFor.SingleEvent <string>( cancellationToken, null, a => Grbl.OnResponseReceived += a, a => Grbl.OnResponseReceived -= a, 1000, () => Comms.com.WriteByte(GrblLegacy.ConvertRTCommand(GrblConstants.CMD_STATUS_REPORT))); }).Start(); while (res == null) { EventUtils.DoEvents(); } Grbl.Poller.SetState(AppConfig.Settings.Base.PollInterval); if (Grbl.GrblState.State == GrblStates.Alarm) { Message = GrblAlarms.GetMessage(Grbl.GrblState.Substate.ToString()); res = false; } if (res == true && Grbl.Signals.Value.HasFlag(Signals.Probe)) { Message = "Probing failed, probe signal is asserted"; res = false; } if (res == true && Grbl.GrblState.State != GrblStates.Idle) { Message = "Probing failed, Grbl is not in idle state"; res = false; } Program.Clear(); if (res != true) // Reenable status polling if int fails { Grbl.Poller.SetState(AppConfig.Settings.Base.PollInterval); } return(res == true); }
public CoordinatesControl() { InitializeComponent(); grbl = Grbl.Interface; DataContext = new CoordinatesViewModel(); }