Exemple #1
0
    def print_gcode_file(self, id):
        """
        Print gcode file with given `id`.

        :param id: ID of the gcode file to get.
        :type id: :class:`int`
        """
        if PRINTER['state'] != opengb.printer.State.READY:
            raise IndexError('Printer not ready')
        try:
            OGD.GCodeFile.get(OGD.GCodeFile.id == id)
        except OGD.GCodeFile.DoesNotExist:
            raise IndexError('No gcode file found with id {0}'.format(id))
        try:
            gcode = OGU.prepare_gcode(OGU.load_gcode_file(id))
        except IOError as err:
            LOGGER.error('Error reading gcode file with id {0}: '
                         '{1}'.format(id, err))
            raise IndexError('Error reading gcode file with '
                             'id {0}'.format(id))
        self._to_printer.put({
            'method': 'execute_gcode',
            'params': {
                'gcode_sequence': gcode,
            }
        })
        return True
Exemple #2
0
 def test_gcode_lines_parsed(self):
     """Lines containing valid gcode are included."""
     g = "M107\nM190 S115\nM104 S205\nG28\nG1 Z5 F5000"
     self.assertListEqual(
         utils.prepare_gcode(g),
         ['M107', 'M190 S115', 'M104 S205', 'G28', 'G1 Z5 F5000'])
Exemple #3
0
 def test_partial_line_comments_removed(self):
     """Comments spanning part of a line are removed."""
     g = "M107\nM190 S115;this is a comment\nM104 S205\nG28\nG1 Z5 F5000"
     self.assertListEqual(
         utils.prepare_gcode(g),
         ['M107', 'M190 S115', 'M104 S205', 'G28', 'G1 Z5 F5000'])
Exemple #4
0
 def test_blank_lines_removed(self):
     """Blank lines are removed."""
     g = "M107\nM190 S115\n\n\n\nM104 S205\nG28\nG1 Z5 F5000"
     self.assertListEqual(
         utils.prepare_gcode(g),
         ['M107', 'M190 S115', 'M104 S205', 'G28', 'G1 Z5 F5000'])