public EngineCommandResult ProcessAllCommands() { if (ActiveCommands.Count == 0) { return(EngineCommandResult.Success); } //if (!Proxy.CheckAllInitialized) // return ( EngineCommandResult.Failed ); var res = EngineCommandResult.Success; foreach (var c in ActiveCommands) { Proxy.Core.Log.Info("[Proxy Command Processor] Starting command: " + c.Type); res = ProcessCommand(c); if (res == EngineCommandResult.CriticalFailed) { break; } } ActiveCommands.Clear(); return(res); }
private void MachineConnection_LineReceived(string line) { if (line.StartsWith("<")) { Match statusMatch = StatusEx.Match(line); if (!statusMatch.Success) { Console.WriteLine("Received Bad Status: '{0}'", line); return; } Group status = statusMatch.Groups["State"]; if (status.Success) { Status = status.Value; } Group mx = statusMatch.Groups["MX"], my = statusMatch.Groups["MY"], mz = statusMatch.Groups["MZ"]; if (mx.Success) { MachinePosition = new Vector3(double.Parse(mx.Value, GCodeCommand.NumberFormat), double.Parse(my.Value, GCodeCommand.NumberFormat), double.Parse(mz.Value, GCodeCommand.NumberFormat)); } Group wx = statusMatch.Groups["WX"], wy = statusMatch.Groups["WY"], wz = statusMatch.Groups["WZ"]; if (wx.Success) { WorkPosition = new Vector3(double.Parse(wx.Value, GCodeCommand.NumberFormat), double.Parse(wy.Value, GCodeCommand.NumberFormat), double.Parse(wz.Value, GCodeCommand.NumberFormat)); } StatusUpdate(); } else if (line.StartsWith("ok")) { if (ActiveCommands.Count > 0) { CharBufferCount -= ActiveCommands.Dequeue().Length; } else { Console.WriteLine("Received ok without active command"); } } else if (line.StartsWith("[PRB:")) { Match probeMatch = ProbeEx.Match(line); Group mx = probeMatch.Groups["MX"]; if (!probeMatch.Success || !mx.Success) { Console.WriteLine("Received Bad Probe: '{0}'", line); return; } double height = double.Parse(mx.Value, GCodeCommand.NumberFormat); height += WorkPosition.Z - MachinePosition.Z; if (Probes.Count > 0) { Probes.Dequeue().SetResult(height); } } else if (line.StartsWith("error")) { string command; if (ActiveCommands.Count > 0) { command = ActiveCommands.Dequeue(); CharBufferCount -= command.Length; } else { command = "No active command"; } HandleError(line, command); } else if (line.StartsWith("[")) //feedback message { } else if (line.StartsWith("ALARM")) { } else if (line.StartsWith("Grbl")) { Probes.Clear(); ActiveCommands.Clear(); CharBufferCount = 0; RequestStatus(); } }