public void receiveLine(GCode code) { bytesin += code.orig.Length; ana.Analyze(code); lock (output) { if (code.hasM) { switch (code.M) { case 115: // Firmware output.AddLast("FIRMWARE_NAME:RepetierVirtualPrinter FIRMWARE_URL:https://github.com/repetier/Repetier-Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1 REPETIER_PROTOCOL:1"); //output.AddLast("FIRMWARE_NAME:Marlin FIRMWARE_URL:https://github.com/repetier/Repetier-Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1 REPETIER_PROTOCOL:1"); break; case 105: // Print Temperatures output.AddLast("T:" + extruderTemp.ToString("0") + " B:" + bedTemp.ToString("0") + " @:" + extruderOut.ToString("0")); break; case 205: // EEPROM Settings output.AddLast("EPR:2 75 76800 Baudrate"); output.AddLast("EPR:2 79 0 Max. inactive time [ms,0=off]"); output.AddLast("EPR:2 83 60000 Stop stepper afer inactivity [ms,0=off]"); output.AddLast("EPR:3 3 40.00 X-axis steps per mm"); output.AddLast("EPR:3 7 40.00 Y-axis steps per mm"); output.AddLast("EPR:3 11 3333.59 Z-axis steps per mm"); output.AddLast("EPR:3 15 20000.00 X-axis max. feedrate [mm/min]"); output.AddLast("EPR:3 19 20000.00 Y-axis max. feedrate [mm/min]"); output.AddLast("EPR:3 23 2.00 Z-axis max. feedrate [mm/min]"); output.AddLast("EPR:3 27 1500.00 X-axis homing feedrate [mm/min]"); output.AddLast("EPR:3 31 1500.00 Y-axis homing feedrate [mm/min]"); output.AddLast("EPR:3 35 100.00 Z-axis homing feedrate [mm/min]"); output.AddLast("EPR:3 39 20.00 X-axis start speed [mm/s]"); output.AddLast("EPR:3 43 20.00 Y-axis start speed [mm/s]"); output.AddLast("EPR:3 47 1.00 Z-axis start speed [mm/s]"); output.AddLast("EPR:3 51 750.00 X-axis acceleration [mm/s^2]"); output.AddLast("EPR:3 55 750.00 Y-axis acceleration [mm/s^2]"); output.AddLast("EPR:3 59 50.00 Z-axis acceleration [mm/s^2]"); output.AddLast("EPR:3 63 750.00 X-axis travel acceleration [mm/s^2]"); output.AddLast("EPR:3 67 750.00 Y-axis travel acceleration [mm/s^2]"); output.AddLast("EPR:3 71 50.00 Z-axis travel acceleration [mm/s^2]"); output.AddLast("EPR:3 150 373.00 Extr. steps per mm"); output.AddLast("EPR:3 154 1200.00 Extr. max. feedrate [mm/min]"); output.AddLast("EPR:3 158 10.00 Extr. start feedrate [mm/s]"); output.AddLast("EPR:3 162 10000.00 Extr. acceleration [mm/s^2]"); output.AddLast("EPR:0 166 1 Heat manager [0-1]"); output.AddLast("EPR:0 167 130 PID drive max"); output.AddLast("EPR:2 168 300 PID P-gain [*0.01]"); output.AddLast("EPR:2 172 2 PID I-gain [*0.01]"); output.AddLast("EPR:2 176 2000 PID D-gain [*0.01]"); output.AddLast("EPR:0 180 200 PID max value [0-255]"); output.AddLast("EPR:2 181 0 X-offset [steps]"); output.AddLast("EPR:2 185 0 Y-offset [steps]"); output.AddLast("EPR:2 189 40 Temp. stabilize time [s]"); break; } } output.AddLast("ok"); } }
public void TrySendNextLine() { string logtext = null; int loglevel = 0; float logprogress = -1; string printeraction = null; GCode historygc = null; try { lock (nextlineLock) { if (pingpong && !readyForNextSend) { return; } if (serial == null) { return; // Not ready yet } if (!serial.IsOpen) // someone unplugged the cord? { close(); return; } GCode gc = null; try { // first resolve old communication problems if (resendNode != null) { gc = resendNode.Value; if (binaryVersion == 0) { string cmd = gc.getAscii(true, true); if (!pingpong && receivedCount() + cmd.Length + 2 > receiveCacheSize) { return; // printer cache full } if (pingpong) { readyForNextSend = false; } else { lock (nackLines) { nackLines.AddLast(cmd.Length + 2); } } serial.WriteLine(cmd); bytesSend += cmd.Length + 2; } else { byte[] cmd = gc.getBinary(binaryVersion); if (!pingpong && receivedCount() + cmd.Length > receiveCacheSize) { return; // printer cache full } if (pingpong) { readyForNextSend = false; } else { lock (nackLines) { nackLines.AddLast(cmd.Length); } } serial.Write(cmd, 0, cmd.Length); bytesSend += cmd.Length; } linesSend++; lastCommandSend = DateTime.Now.Ticks; resendNode = resendNode.Next; logtext = "Resend: " + gc.getAscii(true, true); // if (resendNode == null) readyForNextSend = true; //readyForNextSend = false; return; } if (resendError > 0) { resendError--; // Drop error counter } // then check for manual commands if (injectCommands.Count > 0) { lock (history) { gc = injectCommands.First.Value; gc.N = ++lastline; if (binaryVersion == 0) { string cmd = gc.getAscii(true, true); if (!pingpong && receivedCount() + cmd.Length + 2 > receiveCacheSize) { --lastline; return; } // printer cache full if (pingpong) { readyForNextSend = false; } else { lock (nackLines) { nackLines.AddLast(cmd.Length); } } serial.WriteLine(cmd); bytesSend += cmd.Length + 2; } else { byte[] cmd = gc.getBinary(binaryVersion); if (!pingpong && receivedCount() + cmd.Length > receiveCacheSize) { --lastline; return; } // printer cache full if (pingpong) { readyForNextSend = false; } else { lock (nackLines) { nackLines.AddLast(cmd.Length); } } serial.Write(cmd, 0, cmd.Length); bytesSend += cmd.Length; } injectCommands.RemoveFirst(); } linesSend++; lastCommandSend = DateTime.Now.Ticks; historygc = gc; analyzer.Analyze(gc); if (job.dataComplete == false) { if (injectCommands.Count == 0) { printeraction = "Idle"; } else { printeraction = injectCommands.Count.ToString() + " commands waiting"; } } return; } // do we have a printing job? if (job.dataComplete) { lock (history) { gc = job.PeekData(); gc.N = ++lastline; if (binaryVersion == 0) { string cmd = gc.getAscii(true, true); if (!pingpong && receivedCount() + cmd.Length + 2 > receiveCacheSize) { --lastline; return; } // printer cache full if (pingpong) { readyForNextSend = false; } else { lock (nackLines) { nackLines.AddLast(cmd.Length + 2); } } serial.WriteLine(cmd); bytesSend += cmd.Length + 2; } else { byte[] cmd = gc.getBinary(binaryVersion); if (!pingpong && receivedCount() + cmd.Length > receiveCacheSize) { --lastline; return; } // printer cache full if (pingpong) { readyForNextSend = false; } else { lock (nackLines) { nackLines.AddLast(cmd.Length); } } serial.Write(cmd, 0, cmd.Length); bytesSend += cmd.Length; } historygc = gc; job.PopData(); } linesSend++; lastCommandSend = DateTime.Now.Ticks; analyzer.Analyze(gc); printeraction = "Printing...ETA " + job.ETA; logprogress = job.PercentDone; } } catch (InvalidOperationException ex) { logtext = "Error sending data:" + ex; loglevel = 2; } } } finally { // need to extract log/event calls because they cause deadlocks inside // the lock statement. if (historygc != null) { StoreHistory(historygc); } if (logtext != null) { log(logtext, false, loglevel); } if (printeraction != null) { firePrinterAction(printeraction); } if (logprogress >= 0 && eventJobProgress != null) { Main.main.Invoke(eventJobProgress, job.PercentDone); } } }
/// <summary> /// Add a GCode line to be visualized. /// </summary> /// <param name="g"></param> public void AddGCode(GCode g) { act = g; ana.Analyze(g); laste = ana.emax; }