private void BT_GO_Click(object sender, EventArgs e) { CB_BED.ForeColor = Color.Black; if (CB_BED.Checked) { int dummy; if (!Int32.TryParse(TB_HOTEND_TEMP.Text, out dummy)) { CB_BED.ForeColor = Color.Maroon; return; } if (!Int32.TryParse(TB_BED_TEMP.Text, out dummy)) { CB_BED.ForeColor = Color.Maroon; return; } if (!Int32.TryParse(TB_BEDX.Text, out dummy)) { CB_BED.ForeColor = Color.Maroon; return; } if (!Int32.TryParse(TB_BEDY.Text, out dummy)) { CB_BED.ForeColor = Color.Maroon; return; } } for (int i = 0; i < 300; i++) { if (Dialogues[i] != null) { Dialogues[i].Dispose(); Dialogues[i] = null; } } if (WarningSent) { StartSearchThread(); } else if (Int32.Parse(TB_BEDY.Text) < 100 || Int32.Parse(TB_BEDX.Text) < 100 || Int32.Parse(TB_BED_TEMP.Text) < 50 || Int32.Parse(TB_HOTEND_TEMP.Text) < 150) { WarningSent = true; Dialogues[positionIndex] = new WarningDialogue("Tool settings seem low, this could lead to many messages. Continue -> Retry", "ER1", 2, line, positionIndex, this); } else { StartSearchThread(); } }
void SearchMethod() { using (FileStream fs = new FileStream(OF_GCODE.FileName, FileMode.Open)) { using (StreamReader sr = new StreamReader(fs)) { while (!sr.EndOfStream && !cancel) { if (positionIndex == 1000) { if (Dialogues[1] != null) { Dialogues[1].Dispose(); } Dialogues[1] = new WarningDialogue("Too Many Errors! Wrong settings?", "0000", 0, line, 1, this); positionIndex = 0; break; } string currentLine = sr.ReadLine(); line++; if (!currentLine.StartsWith(";")) { if (currentLine.StartsWith("M190 ") && CB_BED.Checked) { int value; Int32.TryParse(currentLine.Substring(currentLine.IndexOf("S") + 1), out value); if (value > Convert.ToInt32(TB_BED_TEMP.Text)) { Dialogues[positionIndex] = new WarningDialogue("Bed Temperature Exceeds Set Temperature", "M190", 2, line, positionIndex, this); positionIndex++; } } if (currentLine.StartsWith("M104 ") && CB_BED.Checked) { int value; Int32.TryParse(currentLine.Substring(currentLine.IndexOf("S") + 1), out value); if (value > Convert.ToInt32(TB_HOTEND_TEMP.Text)) { Dialogues[positionIndex] = new WarningDialogue("Hotend Temperature Exceeds Set Temperature", "M104", 2, line, positionIndex, this); positionIndex++; } } if (currentLine.StartsWith("G1 ") && CB_BED.Checked && currentLine.Contains("E") && currentLine.Contains("X") && currentLine.Contains("Y")) { currentLine = currentLine.Replace(".", ","); double posX; double posY; Double.TryParse(currentLine.Substring(currentLine.IndexOf("X") + 1, Math.Abs(currentLine.IndexOf("X") - currentLine.IndexOf("Y")) - 1), out posX); Double.TryParse(currentLine.Substring(currentLine.IndexOf("Y") + 1, Math.Abs(currentLine.IndexOf("Y") - currentLine.IndexOf("E")) - 1), out posY); if (RB_BED_BL.Checked) { if (posX < 0 || posX > Convert.ToInt32(TB_BEDX.Text)) { Dialogues[positionIndex] = new WarningDialogue("Head moves out of Bounds in X", "G1", 1, line, positionIndex, this); positionIndex++; } if (posY < 0 || posY > Convert.ToInt32(TB_BEDY.Text)) { Dialogues[positionIndex] = new WarningDialogue("Head moves out of Bounds in Y", "G1", 1, line, positionIndex, this); positionIndex++; } } else { if (posX < -Convert.ToInt32(TB_BEDX.Text) / 2 || posX > Convert.ToInt32(TB_BEDX.Text) / 2) { Dialogues[positionIndex] = new WarningDialogue("Head moves out of Bounds in X", "G1", 1, line, positionIndex, this); positionIndex++; } if (posY < -Convert.ToInt32(TB_BEDY.Text) / 2 || posX > Convert.ToInt32(TB_BEDY.Text) / 2) { Dialogues[positionIndex] = new WarningDialogue("Head moves out of Bounds in Y", "G1", 1, line, positionIndex, this); positionIndex++; } } } if (currentLine.StartsWith("M500")) { M500Found = true; EEPROMLine = line; } if (currentLine.StartsWith("M502") && CB_M502.Checked) { Dialogues[positionIndex] = new WarningDialogue("EEPROM Settings are Factory Reset! (M500 saved?)", "M502", 0, line, positionIndex, this); positionIndex++; } if ((currentLine.StartsWith("M906") || currentLine.StartsWith("M907")) && CB_M906.Checked) { Dialogues[positionIndex] = new WarningDialogue("Stepper motor amperage is changed!", "M907", 0, line, positionIndex, this); positionIndex++; } if (CB_G20.Checked && currentLine.StartsWith("G20")) { Dialogues[positionIndex] = new WarningDialogue("Units are changed to Inches. Boundary check no longer possible", "G20", 2, line, positionIndex, this); positionIndex++; } if (CB_G91.Checked && currentLine.StartsWith("G91")) { Dialogues[positionIndex] = new WarningDialogue("Positioning is set to relative. Boundary check no longer possible", "G91", 2, line, positionIndex, this); positionIndex++; } if (CB_M92.Checked && currentLine.StartsWith("M92")) { Dialogues[positionIndex] = new WarningDialogue("E-Steps are changed. Boundary check no longer possible", "M92", 1, line, positionIndex, this); positionIndex++; } if (CB_M110.Checked && currentLine.StartsWith("M110")) { int lineNumber = Int32.Parse(currentLine.Substring(currentLine.IndexOf("N") + 1)); if (lineNumber < line) { Dialogues[positionIndex] = new WarningDialogue("Goes to a previous line. Infinite Loop expected", "M110", 2, line, positionIndex, this); positionIndex++; } } if (CB_M149.Checked && currentLine.StartsWith("M149")) { Dialogues[positionIndex] = new WarningDialogue("Temperature changed to a different Scale", "M149", 2, line, positionIndex, this); positionIndex++; } if (CB_M203.Checked && currentLine.StartsWith("M203")) { Dialogues[positionIndex] = new WarningDialogue("Maximum Feedrate changed to: " + currentLine.Substring(currentLine.IndexOf("M203") + 5), "M203", 1, line, positionIndex, this); positionIndex++; } if (CB_M201.Checked && currentLine.StartsWith("M201")) { Dialogues[positionIndex] = new WarningDialogue("Maximum Acceleration changed to: " + currentLine.Substring(currentLine.IndexOf("M201") + 5), "M201", 1, line, positionIndex, this); positionIndex++; } if (CB_M206.Checked && currentLine.StartsWith("M206")) { Dialogues[positionIndex] = new WarningDialogue("Home offsets changed: " + currentLine.Substring(currentLine.IndexOf("M206") + 5), "M206", 1, line, positionIndex, this); positionIndex++; } if (CB_M211.Checked && currentLine.StartsWith("M211")) { Dialogues[positionIndex] = new WarningDialogue("Enables virtual Software endstops", "M211", 2, line, positionIndex, this); positionIndex++; } if (CB_M220.Checked && currentLine.StartsWith("M220")) { Dialogues[positionIndex] = new WarningDialogue("Changes Flowrate to: " + currentLine.Substring(currentLine.IndexOf("S") + 1) + "%", "M220", 2, line, positionIndex, this); positionIndex++; } if (CB_M301.Checked && currentLine.StartsWith("M301")) { Dialogues[positionIndex] = new WarningDialogue("Manual Hotend PID Tune: " + currentLine.Substring(currentLine.IndexOf("M301") + 5), "M301", 1, line, positionIndex, this); positionIndex++; } if (CB_M302.Checked && currentLine.StartsWith("M302")) { Dialogues[positionIndex] = new WarningDialogue("Minimum Extrude Temperature changed to :" + currentLine.Substring(currentLine.IndexOf("S") + 1), "M302", 2, line, positionIndex, this); positionIndex++; } if (CB_M303.Checked && currentLine.StartsWith("M303")) { Dialogues[positionIndex] = new WarningDialogue("PID Autotune Start", "M303", 1, line, positionIndex, this); positionIndex++; } if (CB_M304.Checked && currentLine.StartsWith("M304")) { Dialogues[positionIndex] = new WarningDialogue("Manual Heatbed PID Tune: " + currentLine.Substring(currentLine.IndexOf("M304") + 5), "M304", 1, line, positionIndex, this); positionIndex++; } if (CB_M350.Checked && currentLine.StartsWith("M350")) { Dialogues[positionIndex] = new WarningDialogue("Microsteps changed for X_MS1 or Y_MS1 pins", "M350", 2, line, positionIndex, this); positionIndex++; } if (CB_M401.Checked && currentLine.StartsWith("M401")) { if (line > 50) { Dialogues[positionIndex] = new WarningDialogue("ABL Probe deployed mid-print!", "M401", 0, line, positionIndex, this); positionIndex++; } } if (CB_M410.Checked && currentLine.StartsWith("M410")) { Dialogues[positionIndex] = new WarningDialogue("Quickstop triggered. Position has to be homed again. Resume will result in failure", "M410", 2, line, positionIndex, this); positionIndex++; } if (CB_M428.Checked && currentLine.StartsWith("M428")) { Dialogues[positionIndex] = new WarningDialogue("Homeposition set Mid-Print! Highly unusual for normal slicers", "M428", 0, line, positionIndex, this); positionIndex++; } } } if (M500Found) { Dialogues[0] = new WarningDialogue("Some Settings are Saved to EEPROM!", "M500", 0, EEPROMLine, 0, this); } else { Dialogues[0] = new WarningDialogue("No EEPROM-Save detected", "M500", 3, line, 0, this); } cancel = false; this.Invoke((MethodInvoker) delegate { BT_GO.Enabled = true; BT_ABORT.Enabled = false; TB_BEDY.Enabled = true; TB_BEDX.Enabled = true; TB_BED_TEMP.Enabled = true; TB_HOTEND_TEMP.Enabled = true; CB_BED.Enabled = true; CB_ALL.Enabled = true; BT_OPEN.Enabled = true; foreach (Control control in PA_SETTINGS.Controls) { control.Enabled = true; } }); } } }