public bool Execute(bool go) { _isComplete = isProbing = false; probing.ClearExeStatus(); if (_program.Count > 0) { step = 0; probing.Positions.Clear(); probing.Machine.Clear(); Comms.com.PurgeQueue(); if (!isRunning) { isRunning = true; probeProtect = GrblInfo.HasSimpleProbeProtect; Grbl.OnCommandResponseReceived += ResponseReceived; Grbl.PropertyChanged += Grbl_PropertyChanged; if (hasPause) { probing.PropertyChanged += Probing_PropertyChanged; } } Grbl.IsJobRunning = true; if (probing.Message == string.Empty) { probing.Message = "Probing..."; } Grbl.ExecuteCommand(_program[step]); while (!_isComplete) { EventUtils.DoEvents(); } } return(probing.IsSuccess); }
public bool Execute(bool go) { _isComplete = isProbing = false; probing.ClearExeStatus(); if (_program.Count > 0) { string response; step = 0; probing.Positions.Clear(); probing.Machine.Clear(); Comms.com.PurgeQueue(); if (!isRunning) { isRunning = true; probeProtect = GrblInfo.HasSimpleProbeProtect; Grbl.OnCommandResponseReceived += ResponseReceived; Grbl.PropertyChanged += Grbl_PropertyChanged; if (hasPause) { probing.PropertyChanged += Probing_PropertyChanged; } } Grbl.IsJobRunning = true; if (probing.Message == string.Empty) { probing.Message = LibStrings.FindResource("Probing"); } cmd_response = string.Empty; Grbl.ExecuteCommand(_program[step]); while (!_isComplete) { EventUtils.DoEvents(); if (cmd_response != string.Empty) { response = cmd_response; cmd_response = string.Empty; if (Grbl.ResponseLogVerbose) { Grbl.ResponseLog.Add("PM:" + response); } if (response == "ok") { step++; if (step < _program.Count) { int i; //if ((i = _program[step].IndexOf('$')) > 0) //{ // string rp = _program[step].Substring(i, 2); // i = GrblInfo.AxisLetterToIndex(rp[1]); // double val = _positions[_positions.Count - 1].Values[i] + dbl.Parse(_program[step].Substring(i, 3)); // _program[step] = _program[step] + val.ToInvariantString(); //} if (_program[step].StartsWith("!")) { isProbing = false; _program[step] = _program[step].Substring(1); probing.RemoveLastPosition(); } if (_program[step] == "pause") { probing.IsPaused = true; probeOnCycleStart = !probing.Grbl.Signals.Value.HasFlag(Signals.CycleStart); } else { // This fails with a hang if probe is asserted when it should not be... //if ((isProbing = _program[step].Contains("G38")) && !IsProbeReady()) // response = "probe!"; //else Grbl.ExecuteCommand(_program[step]); } } } if (step == _program.Count || response != "ok") { probing.IsSuccess = step == _program.Count && response == "ok"; if (!probing.IsSuccess && response != "probe!") { End(LibStrings.FindResource(Grbl.GrblState.State == GrblStates.Alarm ? "FailedAlarm" : "FailedCancelled")); } _isComplete = probing.IsCompleted = true; } } } if (probing.Message == LibStrings.FindResource("Probing")) { probing.Message = string.Empty; } } return(probing.IsSuccess); }