public void updateStatus() { TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1)); long timestamp = (long)t.TotalSeconds; long diff = timestamp - statusSet; float etemp = ann.getTemperature(ann.activeExtruderId); if (Main.conn.connector.IsConnected() == false) { if (status != PrinterStatus.disconnected) { Status = PrinterStatus.disconnected; } } else if (etemp > 15 && etemp - con.getTemperature(-1) > 5) { Status = PrinterStatus.heatingExtruder; } else if (ann.bedTemp > 15 && ann.bedTemp - con.bedTemp > 5 && con.bedTemp > 15) // only if has bed { Status = PrinterStatus.heatingBed; } else if (status == PrinterStatus.heatingBed || status == PrinterStatus.heatingExtruder) { Status = PrinterStatus.idle; } else if (Main.conn.connector.IsPaused && status != PrinterStatus.jobPaused) { Status = PrinterStatus.jobPaused; } else if (status == PrinterStatus.jobPaused && !Main.conn.connector.IsPaused) { Status = PrinterStatus.idle; } else if (status == PrinterStatus.idle && diff > 0) { Status = PrinterStatus.idle; } else if (status == PrinterStatus.motorStopped || status == PrinterStatus.jobKilled || status == PrinterStatus.jobFinsihed) { if (diff > 30) // remove message after 30 seconds { Status = PrinterStatus.idle; } } else if (status == PrinterStatus.disconnected && Main.conn.connector.IsConnected()) { Status = PrinterStatus.idle; } }
/// <summary> /// Analyzes a response from the printer. /// Updates data and sends events according to the data. /// </summary> /// <param name="res"></param> public void analyzeResponse(string res, ref int level) { while (res.Length > 0 && res[0] < 32) { res = res.Substring(1); } res = res.Trim(); bool ignoreFB = shouldIgnoreFeedback(); if (logWriter != null) { DateTime time = DateTime.Now; lock (logWriter) { logWriter.WriteLine("> " + time.Hour.ToString("00") + ":" + time.Minute.ToString("00") + ":" + time.Second.ToString("00") + "." + time.Millisecond.ToString("000") + " : " + res); } } if (eventResponse != null) { eventResponse(res); } string h = extract(res, "FIRMWARE_NAME:"); if (h != null) { level = 3; firmware = h; h = h.ToLower(); if (h.IndexOf("repetier") >= 0) { isRepetier = true; } if (h.IndexOf("marlin") >= 0) { isMarlin = true; } if (h.IndexOf("sprinter") >= 0) { isSprinter = true; } if (isMarlin || isRepetier || isSprinter) // Activate special menus and function { /* PTITSYN * Main.main.Invoke(Main.main.UpdateEEPROM); */ injectManualCommand("M220 S" + speedMultiply.ToString()); injectManualCommand("M221 S" + flowMultiply.ToString()); } /* PTITSYN * * Main.main.Invoke(Main.main.FirmwareDetected); */ } h = extract(res, "FIRMWARE_URL:"); if (h != null) { level = 3; firmware_url = h; } h = extract(res, "PROTOCOL_VERSION:"); if (h != null) { level = 3; protocol = h; } h = extract(res, "MACHINE_TYPE:"); if (h != null) { level = 3; machine = h; } h = extract(res, "EXTRUDER_COUNT:"); if (h != null) { level = 3; if (!int.TryParse(h, out numberExtruder)) { numberExtruder = 1; } } h = extract(res, "X:"); if (h != null) { level = 3; float.TryParse(h, NumberStyles.Float, GCode.format, out x); analyzer.x = x; //analyzer.hasXHome = true; } h = extract(res, "Y:"); if (h != null) { level = 3; float.TryParse(h, NumberStyles.Float, GCode.format, out y); analyzer.y = y; //analyzer.hasYHome = true; } h = extract(res, "Z:"); if (h != null) { level = 3; float.TryParse(h, NumberStyles.Float, GCode.format, out z); analyzer.z = z; // analyzer.hasZHome = true; } h = extract(res, "E:"); if (h != null) { level = 3; float.TryParse(h, NumberStyles.Float, GCode.format, out e); analyzer.activeExtruder.e = e; } if (!ignoreFB) { if ((h = extract(res, "SpeedMultiply:")) != null) { int.TryParse(h, out speedMultiply); if (speedMultiply < 25) { speedMultiply = 25; } if (speedMultiply > 300) { speedMultiply = 300; } analyzer.fireChanged(); } if ((h = extract(res, "FlowMultiply:")) != null) { int.TryParse(h, out flowMultiply); if (flowMultiply < 50) { flowMultiply = 50; } if (flowMultiply > 150) { flowMultiply = 150; } analyzer.fireChanged(); } } if ((h = extract(res, "TargetExtr0:")) != null) { float et; float.TryParse(h, NumberStyles.Float, GCode.format, out et); analyzer.setTemperature(0, et); analyzer.fireChanged(); } if ((h = extract(res, "TargetExtr1:")) != null) { float et; float.TryParse(h, NumberStyles.Float, GCode.format, out et); analyzer.setTemperature(1, et); analyzer.fireChanged(); } if ((h = extract(res, "TargetBed:")) != null) { float.TryParse(h, NumberStyles.Float, GCode.format, out analyzer.bedTemp); analyzer.fireChanged(); } if ((h = extract(res, "Fanspeed:")) != null) { int.TryParse(h, out analyzer.fanVoltage); analyzer.fanOn = analyzer.fanVoltage > 0; analyzer.fireChanged(); } if (res.Contains("RequestPause:")) { /* PTITSYN * * Main.main.Invoke(firmwareRequestedPause); */ } bool tempChange = false; h = extract(res, "T0:"); if (h != null) { multiTempRead = true; int n = 0; level = -1; // dont log, we see result in status //if (h.IndexOf('.') > 0) h = h.Substring(0, h.IndexOf('.')); do { float et; float.TryParse(h, NumberStyles.Float, GCode.format, out et); tempChange = true; setTemperature(n, et); h = extract(res, "@" + n + ":"); int eo = -1; int.TryParse(h, out eo); if (isMarlin) { eo *= 2; } setOutput(n, eo); n++; h = extract(res, "T" + n + ":"); } while (h != null); } else { h = extract(res, "T:"); if (h != null) { level = -1; // dont log, we see result in status //if (h.IndexOf('.') > 0) h = h.Substring(0, h.IndexOf('.')); float et; float.TryParse(h, NumberStyles.Float, GCode.format, out et); setTemperature(-1, et); tempChange = true; int eo = -1; h = extract(res, "@:"); int.TryParse(h, out eo); if (isMarlin) { eo *= 2; } setOutput(-1, eo); } } h = extract(res, "B:"); if (h != null) { level = -1; // don't log, we see result in status //if (h.IndexOf('.') > 0) h = h.Substring(0, h.IndexOf('.')); float.TryParse(h, NumberStyles.Float, GCode.format, out bedTemp); tempChange = true; } h = extract(res, "RAW0:"); if (h != null) { level = 3; // don't log, we see result in status } if (isRepetier) { // Repetier specific answers if (res.StartsWith("EPR:")) { eeprom.Add(res); } } if (isMarlin) { // Marlin specifix answers if (res.StartsWith("echo:") && (res.IndexOf("M92") > 0) || (res.IndexOf("M203") > 0) || (res.IndexOf("M201") > 0) || (res.IndexOf("M204") > 0) || (res.IndexOf("M205") > 0) || (res.IndexOf("M206") > 0) || (res.IndexOf("M301") > 0)) { eepromm.Add(res); } } if (res.StartsWith("MTEMP:")) // Temperature monitor { level = -1; // this happens to often to log. Temperture monitor i sthe log string[] sl = res.Substring(6).Split(' '); if (sl.Length == 4) { UInt32 time; int temp, target, output; UInt32.TryParse(sl[0], out time); int.TryParse(sl[1], out temp); int.TryParse(sl[2], out target); int.TryParse(sl[3], out output); if (time > 0 && eventTempMonitor != null) { try { /* PTITSYN * * Main.main.Invoke(eventTempMonitor, time, temp, target, output); */ } catch { } } if (eventTempHistory != null) { /* PTITSYN * * TemperatureEntry te = new TemperatureEntry(analyzer.tempMonitor, temp, output, analyzer.bedTemp, analyzer.getTemperature(-1)); * Main.main.Invoke(eventTempHistory, te); */ } } } if (extract(res, "Error:") != null) { level = 2; // PTITSYN RepetierHost.view.SoundConfig.PlayError(false); } if (tempChange && eventTempChange != null) { /* PTITSYN */ //Main.main.Invoke(eventTempChange, getTemperature(-1), bedTemp); Application.Current.Dispatcher.Invoke(() => { Application.Current.MainWindow.Dispatcher.Invoke(eventTempChange, getTemperature(-1), bedTemp); }); // Application.Current.MainWindow.Dispatcher.Invoke(eventTempChange, getTemperature(-1), bedTemp); // System.Windows.Application.Current.Dispatcher.Invoke((Action)() => // { //Window owner = System.Windows.Application.Current.MainWindow; // Use owner here - it must be used on the UI thread as well.. //ShowMyWindow(owner); ///}); } if (tempChange && eventTempHistory != null) { TemperatureEntry te = new TemperatureEntry(getTemperature(-1), bedTemp, analyzer.bedTemp, analyzer.getTemperature(-1)); if (getOutput(-1) >= 0) { te.output = getOutput(-1); } /* PTITSYN * Main.main.Invoke(eventTempHistory, te); */ } if (res.StartsWith(" ")) { level = 3; } }