public void ShouldFindG0_X10CommandAsG0WithX10() { var parser = new GCodeParser(new FakeLogger()); var cmd = parser.ParseLine("G0 X10", 0) as GCodeMotion; Assert.AreEqual(10, cmd.End.X); }
public void ShouldFindG0X0CommandAsG0() { var parser = new GCodeParser(new FakeLogger()); var cmd = parser.ParseLine("G0X0", 0) as GCodeMotion; Assert.AreEqual("G0", cmd.Command); }
public override void endBlock(GCodeParser parser, MachineStatus machineStatus, IDictionary <String, ParsedWord> currentBlock) { String currentLine = parser.getCurrentLine(); const String MachiningPlane = "G18"; String motionMode = base.machine.getMotionMode(); String coordinateSystem = base.machine.getCoordinateSystems(); Vector3D toolAx = motion.GetToolAxis(MachiningPlane, machineStatus); if (currentLine.Contains("MSG")) { MessageBox.Show(currentLine.Substring(4, currentLine.Length - 5)); } if (parser.findWordInBlock(new StringBuilder(currentLine)) != null) { if (!String.IsNullOrEmpty(coordinateSystem)) { int beforeAddCount = listOffset.Count; listOffset.Add(coordinateSystem); if (listOffset.Count > beforeAddCount) { ToolChange(); } } base.StartNXPathSettings(currentBlock); LinearMotion(motionMode, MachiningPlane, currentBlock, machineStatus, toolAx, false); base.CircularMotion(machineStatus, currentBlock, motionMode, MachiningPlane, false); base.ThreadTurnMotion(motionMode, currentBlock, toolAx); base.EndNXPathSettings(currentBlock); } }
protected override bool ProcessLine(string line, Socket socket) { string l = line.ToLower().Trim(); if (l == "exit") { return(false); } LED.Write(false); try { GCodeParser.ParseLine(l); SendString("+\r\n", socket); } catch (Exception ex) { SendString("ERROR: " + ex.Message + "\r\n", socket); } finally { LED.Write(true); } return(true); }
public void SplitArc() { var gcode = new List <string>(); gcode.Add("G00 X9.0 Y1.4000 F200"); gcode.Add("G00 X97.0000 Y1.4000 F200"); gcode.Add("G03 X104.6000 Y9.0000 R7.6"); /*gcode.Add("G00 X104.6000 Y77.0000"); * gcode.Add("G03 X97.0000 Y84.6000 R7.6"); * gcode.Add("G0 X9.0000 Y84.6000"); * gcode.Add("G03 X1.4000 Y77.0000 R7.6"); * gcode.Add("G03 X9.0000 Y1.4000 R7.6");*/ //gcode.Add("G00 X45 Y0"); //gcode.Add("G03 X50 Y5 R5"); var parser = new GCodeParser(new FakeLogger()); parser.Parse(gcode); foreach (var cmd in parser.Commands) { if (cmd is GCodeArc) { var arc = cmd as GCodeArc; arc.U = 97; arc.V = 9; } } }
public void ParseChangeTool() { var parser = new GCodeParser(new FakeLogger()); var line = "M06 T01; 0.8000"; var cmd = parser.ParseLine(line, 0) as ToolChangeCommand; Assert.AreEqual("0.8000", cmd.ToolSize); }
public void ShouldFindG0_Retain1Decimal() { var parser = new GCodeParser(new FakeLogger()); var cmd = parser.ParseLine("G0 X10.4", 0) as GCodeMotion; Assert.AreEqual(10.4, cmd.End.X); Assert.AreEqual("G0 X10.4 Y0 Z0", cmd.Line); }
public void ParseProbeCommand() { var parser = new GCodeParser(new FakeLogger()); var cmd = parser.ParseLine("G38.3 Z-5 F20", 0) as GCodeProbe; Assert.AreEqual("G38.3", cmd.Command); Assert.AreEqual(20, cmd.Feed); }
public void ShouldFindG0_ReturnWHoleNumber() { var parser = new GCodeParser(new FakeLogger()); var cmd = parser.ParseLine("G0 X10.00", 0) as GCodeMotion; Assert.AreEqual(10, cmd.End.X); Assert.AreEqual("G0 X10 Y0 Z0", cmd.Line); }
public void ApplyYOffsetTest() { var parser = new GCodeParser(new FakeLogger()); var cmd = parser.ParseLine("G1 X0 Y30 Z0", 10) as GCodeMotion; cmd.ApplyOffset(0, 10); Assert.AreEqual(40, cmd.End.Y); Assert.AreEqual("G1 X0 Y40 Z0", cmd.Line); }
public void ShouldGenerateG1LineWithOnlyXMove() { var parser = new GCodeParser(new FakeLogger()); parser.State.Position = new Core.Models.Drawing.Vector3(5, 5, 0); var cmd = parser.ParseLine("G0X10", 0) as GCodeMotion; Assert.AreEqual("G0 X10 Z0", cmd.Line); }
public void ShouldAddFeedIfNotExisting() { var parser = new GCodeParser(new FakeLogger()); var cmd = parser.ParseLine("G0 X10 F300", 0) as GCodeMotion; Assert.AreEqual(10, cmd.End.X); Assert.AreEqual(300, cmd.Feed.Value); Assert.AreEqual("G0 X10 Y0 Z0 F300", cmd.Line); }
public void ApplyZeroRotation() { var parser = new GCodeParser(new FakeLogger()); var cmd = parser.ParseLine("G1 X30 Y0", 0) as GCodeLine; cmd.Rotate(0); Assert.AreEqual(30, cmd.End.X); Assert.AreEqual("G1 X30 Y0 Z0", cmd.Line); }
public void ShouldAddSpindleIfNotPresent() { var parser = new GCodeParser(new FakeLogger()); var cmd = parser.ParseLine("G0 X10 S30", 0) as GCodeMotion; Assert.AreEqual(10, cmd.End.X); Assert.AreEqual(30, cmd.SpindleRPM.Value); Assert.AreEqual("G0 X10 Y0 Z0 S30", cmd.Line); }
public void Apply90CC2Rotation() { var parser = new GCodeParser(new FakeLogger()); var cmd = parser.ParseLine("G1 X30 Y0", 0) as GCodeLine; cmd.Rotate(90); Console.WriteLine(cmd.Line); Assert.AreEqual(30, cmd.End.Y); Assert.AreEqual("G1 X0 Y30 Z0", cmd.Line); }
public override void end(GCodeParser parser, MachineStatus machineStatus) { CoordinatOffsetManager.Instance().AddValue(listOffset); mcsData = NXToolsViewModel.Instance.McsData; SCM_CW.Remove(startIndex, endIndex - startIndex); SCM_CW.Insert(startIndex, "MSYS/" + mcsData.OffsetX.ToString("F6") + ";" + mcsData.OffsetY.ToString("F6") + ";" + mcsData.OffsetZ.ToString("F6") + ";" + mcsData.M11.ToString("F9") + ";" + mcsData.M12.ToString("F9") + ";" + mcsData.M13.ToString("F9") + ";" + mcsData.M21.ToString("F9") + ";" + mcsData.M22.ToString("F9") + ";" + mcsData.M23.ToString("F9")).Replace(',', '.'); }
public void ShouldAddSpindleIfChanged() { var parser = new GCodeParser(new FakeLogger()); parser.State.SpindleRPM = 30; var cmd = parser.ParseLine("G0 X10 S25", 0) as GCodeMotion; Assert.AreEqual(10, cmd.End.X); Assert.AreEqual(25, cmd.SpindleRPM.Value); Assert.AreEqual("G0 X10 Y0 Z0 S25", cmd.Line); }
public void ShouldAddFeedIfChanged() { var parser = new GCodeParser(new FakeLogger()); parser.State.Feed = 300; var cmd = parser.ParseLine("G0 X10 F250", 0) as GCodeMotion; Assert.AreEqual(10, cmd.End.X); Assert.AreEqual(250, cmd.Feed.Value); Assert.AreEqual("G0 X10 Y0 Z0 F250", cmd.Line); }
public IdleTimeout(ConfigWrapper config) { this.printer = config.get_printer(); this.reactor = this.printer.get_reactor(); this.gcode = this.printer.lookup_object <GCodeParser>("gcode"); this.toolhead = null; this.printer.register_event_handler("klippy:ready", handle_ready); this.state = "Idle"; this.idle_timeout = config.getfloat("timeout", 600.0, above: 0.0); this.idle_gcode = config.get("gcode", DEFAULT_IDLE_GCODE).Split("\n"); }
public static GCodeFile FromList(IEnumerable <string> file, ILogger logger = null) { var parser = new GCodeParser(logger == null ? Services.Logger : logger); parser.Reset(); parser.Parse(file); return(new GCodeFile(parser.Commands) { FileName = "output.nc" }); }
public static GCodeFile Load(string path, ILogger logger = null) { var parser = new GCodeParser(logger == null ? Services.Logger : logger); parser.Reset(); parser.ParseFile(path); return(new GCodeFile(parser.Commands) { FileName = path.Substring(path.LastIndexOf('\\') + 1) }); }
public virtual void end(GCodeParser parser, MachineStatus machineStatus) { CoordinatOffsetManager.Instance().AddValue(listOffset); // CoordinatOffsetManager.Instance().ClearOffsetList() ; mcsData = NXToolsViewModel.Instance.McsData; SCM_CW.Remove(startIndex, endIndex - startIndex); SCM_CW.Insert(startIndex, "MSYS/" + mcsData.OffsetX.ToString("F6") + ";" + mcsData.OffsetY.ToString("F6") + ";" + mcsData.OffsetZ.ToString("F6") + ";" + mcsData.M11.ToString("F9") + ";" + mcsData.M12.ToString("F9") + ";" + mcsData.M13.ToString("F9") + ";" + mcsData.M21.ToString("F9") + ";" + mcsData.M22.ToString("F9") + ";" + mcsData.M23.ToString("F9")).Replace(',', '.'); // SCM_CW.Append("END-OF-PATH") ; // SCM_CW.Append('\n') ; }
private void StartExecutingGCodeThread() { var timeStart = DateTime.Now; _machine.EnqueueCommands = true; try { if (_settings.IgnoreLimitsDuringExecution) { _machine.IgnoreLimitSwitches(true); } _machine.EnableStepperDrivers(true); var parser = new GCodeParser(); parser.OnProgressNotify += new GCodeParser.OnProgressNotifyEventHandler(GCodeParser_OnProgressNotify); Invoke(new MethodInvoker(() => { parser.WorkspaceOffset = ((OffsetType)cboWCS.SelectedItem).GCodeIdentifier; parser.ToolOffset = ((OffsetType)cboToolOffsets.SelectedItem).GCodeIdentifier; parser.ToolLengthCompensation = chkToolLengthOffset.Checked; })); parser.ExecuteCode(txtGCode.Lines.ToList()); _machine.EnableStepperDrivers(false); if (_settings.IgnoreLimitsDuringExecution) { _machine.IgnoreLimitSwitches(false); } } finally { _machine.EnqueueCommands = false; } _machine.RunQueuedCommands(); _executingGCode = false; var timeElapsed = DateTime.Now.Subtract(timeStart); Invoke(new MethodInvoker(() => { EnableOrDisableMotionFunctions(); toolStripStatusLabel.Text = ""; LogText("Program run time: " + timeElapsed.ToString()); SetMachineWorkingOffset(); // Restore to UI defined offsets })); }
//public object config_error = configfile.error; public Machine(Stream input_fd, QueueListener bglogger, Dictionary <string, object> start_args) { this.bglogger = bglogger; this.start_args = start_args; this.reactor = new SelectReactor(); this.reactor.register_callback(this._connect); this.state_message = message_startup; this.is_shutdown = false; this.run_result = null; var gc = new GCodeParser(this, input_fd); this.objects = new Dictionary <string, object> { { "gcode", gc } }; }
public void Apply() { using (new UIUtils.WaitCursor()) { List <string> gc = GCodeParser.TokensToGCode(GCode.File.Tokens, true); GCode.File.AddBlock(string.Format("Compression applied: {0}", GCode.File.Model.FileName), Core.Action.New); foreach (string block in gc) { GCode.File.AddBlock(block, Core.Action.Add); } GCode.File.AddBlock("", Core.Action.End); } }
public virtual void endBlock(GCodeParser parser, MachineStatus machineStatus, IDictionary <String, ParsedWord> currentBlock) { String currentLine = parser.getCurrentLine(); String MachiningPlane = machine.getActivePlane(); String motionMode = machine.getMotionMode(); String coordinateSystem = machine.getCoordinateSystems(); bool helixMode = false; Vector3D toolAx = motion.GetToolAxis(MachiningPlane, machineStatus); if (parser.findWordInBlock(new StringBuilder(currentLine)) != null) { if (currentBlock.ContainsKey("A") || currentBlock.ContainsKey("B") || currentBlock.ContainsKey("C")) { helixMode = true; } else { helixMode = machineStatus.rotAxMode; } if (!String.IsNullOrEmpty(coordinateSystem)) { int beforeAddCount = listOffset.Count; listOffset.Add(coordinateSystem); if (listOffset.Count > beforeAddCount) { ToolChange(); } } StartNXPathSettings(currentBlock); RotAxisMotion(currentBlock, motionMode, MachiningPlane, machineStatus, Tolerance); LinearMotion(motionMode, MachiningPlane, currentBlock, machineStatus, toolAx, helixMode); CircularMotion(machineStatus, currentBlock, motionMode, MachiningPlane, helixMode); ThreadTurnMotion(motionMode, currentBlock, toolAx); EndNXPathSettings(currentBlock); } }
Task mayak600_calculate_turn(System.Threading.CancellationToken cancellationToken) { StringBuilder strb1 = new StringBuilder(Document.Text); string _fullPath = FileDirectoryName + FileNameExceptExtension + "_M600_Turn.cls"; string _fileNameAddPrefix = FileNameExceptExtension + "_M600_Turn"; StringBuilder paramprog = new StringBuilder(); return(Task.Run(() => { MayakLatheControl_CLS lmcontrolCLS = new MayakLatheControl_CLS(); GCodeParser parser = new GCodeParser(null, strb1, "Mayak", lmcontrolCLS); File.WriteAllText(_fullPath, lmcontrolCLS.SCM_CW.ToString().Replace(';', ',')); NXSessionManager.Instance.ExportClsfToNX(_fullPath, _fileNameAddPrefix, true); // StringBuffer = mcontrolCLS.SCM_CW ; }, cancellationToken )); }
public static void Main() { var device = new XYZGantryDevice(); device.SetStepX((steps) => { }); device.SetStepY((steps) => { }); device.SetStepZ((steps) => { }); device.SetStopX(() => { }); device.SetStopX(() => { }); device.SetStopX(() => { }); var machine = new GCodeMachine(device); var parser = new GCodeParser(machine); //parser.ParseLine("G01 X1 Y1"); parser.ParseLine("G02 X1 Y0 I1 J0"); }
Task okuma_calculate_mill(System.Threading.CancellationToken cancellationToken) { StringBuilder strb1 = new StringBuilder(Document.Text); string _fullPath = FileDirectoryName + FileNameExceptExtension + "_Okuma_Mill.cls"; string _fileNameAddPrefix = FileNameExceptExtension + "_Okuma_Mill"; // File.WriteAllText("Program_S840_Text.txt", strb1.ToString()) ; StringBuilder paramprog = new StringBuilder(); return(Task.Run(() => { MachineControl_CLS mcontrolCLS = new MachineControl_CLS(); GCodeParser parser = new GCodeParser(null, strb1, "Okuma", mcontrolCLS); File.WriteAllText(_fullPath, mcontrolCLS.SCM_CW.ToString().Replace(';', ',')); NXSessionManager.Instance.ExportClsfToNX(_fullPath, _fileNameAddPrefix, false); }, cancellationToken )); }
public void LineSplitTest() { var parser = new GCodeParser(new FakeLogger()); var cmd = parser.ParseLine("G0 X25 Y25", 0) as GCodeMotion; Assert.AreEqual("G0", cmd.Command); var cmds = cmd.Split(5); var first = cmds.First(); Assert.AreEqual(cmd.Start.X, first.Start.X); Assert.AreEqual(cmd.Start.Y, first.Start.Y); Assert.AreEqual(cmd.Start.Z, first.Start.Z); var last = cmds.Last(); Assert.AreEqual(cmd.End.X, last.End.X); Assert.AreEqual(cmd.End.Y, last.End.Y); Assert.AreEqual(cmd.End.Z, last.End.Z); }