def read_temperatures_from_file(self, path_on_disk): enable_bed = self._settings.get_boolean(["enable_bed"]) enable_tool = self._settings.get_boolean(["enable_tool"]) enable_chamber = self._settings.get_boolean(["enable_chamber"]) file = open(path_on_disk, 'r') line = file.readline() max_lines = self._settings.get_int(["max_gcode_lines"]) temperatures = dict() current_tool = "tool0" try: with open(path_on_disk, "r") as file: while max_lines > 0: line = file.readline() if line == "": break if line.startswith("T"): # Select tool new_tool = "tool" + strip_comment(line)[1:].strip() if new_tool == "tool": new_tool = "tool0" if PrinterInterface.valid_heater_regex.match(new_tool): current_tool = new_tool if enable_tool and (line.startswith("M104") or line.startswith("M109") ): # Set tool temperature tool, temperature = self.parse_line(line, current_tool) if temperature != None and tool not in temperatures: temperatures[tool] = temperature if enable_bed and ( line.startswith("M190") or line.startswith("M140")): # Set bed temperature _, temperature = self.parse_line(line) if temperature != None and "bed" not in temperatures: temperatures["bed"] = temperature if enable_chamber and (line.startswith("M191") or line.startswith("M141") ): # Set chamber temperature _, temperature = self.parse_line(line) if temperature != None and "chamber" not in temperatures: temperatures["chamber"] = temperature max_lines -= 1 except: self._logger.exception( "Something went wrong while trying to read the preheat temperature from {}" .format(path_on_disk)) return temperatures
def parse_temp(self, line): line = strip_comment(line) tool = "tool0" temperature = None for item in line.split(" "): if item.startswith("S"): try: value = float(item[1:]) if value > 0: temperature = value except ValueError: self._logger.warn("Error parsing heat command: {}".format(line)) pass if item.startswith("T"): tool = "tool" + item[1:].strip() return tool, temperature
def parse_line(self, line, tool="tool0"): line = strip_comment(line) temperature = None for item in line.split(" "): if item.startswith("S"): try: value = float(item[1:]) if value > 0: temperature = value except ValueError: self._logger.warn( "Error parsing heat command: {}".format(line)) pass if item.startswith("T"): new_tool = "tool" + item[1:].strip() if PrinterInterface.valid_heater_regex.match(new_tool): tool = new_tool return tool, temperature
def read_temperatures_from_file(self, path_on_disk): enable_bed = self._settings.get_boolean(["enable_bed"]) enable_tool = self._settings.get_boolean(["enable_tool"]) file = open(path_on_disk, 'r') line = file.readline() max_lines = 1000 temperatures = dict() tool = "tool0" try: with open(path_on_disk, "r") as file: while max_lines > 0: line = file.readline() if line == "": break if line.startswith("T"): # Select tool tool = "tool" + strip_comment(line)[1:].strip() if tool == "tool": tool = "tool0" if enable_tool and (line.startswith("M104") or line.startswith("M109") ): # Set tool temperature tool, temperature = self.parse_line(line, tool) if temperature != None and tool not in temperatures: temperatures[tool] = temperature if enable_bed and ( line.startswith("M190") or line.startswith("M140")): # Set bed temperature _, temperature = self.parse_line(line) if temperature != None and "bed" not in temperatures: temperatures["bed"] = temperature max_lines -= 1 except: self._logger.exception( "Something went wrong while trying to read the preheat temperature from {}" .format(path_on_disk)) return temperatures
def test_strip_comment(self, input, expected): from octoprint.util import comm self.assertEqual(expected, comm.strip_comment(input))
def process_line(self, line): line = strip_comment(line).strip() if not len(line): return None return line + "\r\n"
def test_strip_comment(self, input, expected): from octoprint.util import comm self.assertEquals(expected, comm.strip_comment(input))