Execute a line of gcode @param string command Gcode command to execute
(self, command)
| 51 | } |
| 52 | |
| 53 | def execute_line(self, command): |
| 54 | """ |
| 55 | Execute a line of gcode |
| 56 | @param string command Gcode command to execute |
| 57 | """ |
| 58 | #If command is in unicode, encode it into ascii |
| 59 | if isinstance(command, unicode): |
| 60 | self._log.debug('{"event":"encoding_gcode_into_utf8"}') |
| 61 | command = command.encode("utf8") |
| 62 | elif not isinstance(command, str): |
| 63 | self._log.error('{"event":"gcode_file_in_improper_format"}') |
| 64 | raise makerbot_driver.Gcode.ImproperGcodeEncodingError |
| 65 | |
| 66 | try: |
| 67 | command = makerbot_driver.Gcode.variable_substitute(command, self.environment) |
| 68 | |
| 69 | codes, flags, comment = makerbot_driver.Gcode.parse_line(command) |
| 70 | |
| 71 | if 'G' in codes: |
| 72 | if codes['G'] in self.GCODE_INSTRUCTIONS: |
| 73 | makerbot_driver.Gcode.check_for_extraneous_codes( |
| 74 | codes.keys(), self.GCODE_INSTRUCTIONS[codes['G']][1]) |
| 75 | makerbot_driver.Gcode.check_for_extraneous_codes( |
| 76 | flags, self.GCODE_INSTRUCTIONS[codes['G']][2]) |
| 77 | self.GCODE_INSTRUCTIONS[codes['G'] |
| 78 | ][0](codes, flags, comment) |
| 79 | |
| 80 | else: |
| 81 | self._log.error('{"event":"unrecognized_command", "command":%s}', codes['G']) |
| 82 | gcode_error = makerbot_driver.Gcode.UnrecognizedCommandError() |
| 83 | gcode_error.values['UnrecognizedCommand'] = codes['G'] |
| 84 | raise gcode_error |
| 85 | |
| 86 | elif 'M' in codes: |
| 87 | if codes['M'] in self.MCODE_INSTRUCTIONS: |
| 88 | makerbot_driver.Gcode.check_for_extraneous_codes( |
| 89 | codes.keys(), self.MCODE_INSTRUCTIONS[codes['M']][1]) |
| 90 | makerbot_driver.Gcode.check_for_extraneous_codes( |
| 91 | flags, self.MCODE_INSTRUCTIONS[codes['M']][2]) |
| 92 | self.MCODE_INSTRUCTIONS[codes['M'] |
| 93 | ][0](codes, flags, comment) |
| 94 | |
| 95 | else: |
| 96 | self._log.error('{"event":"unrecognized_command", "command":%s}', codes['M']) |
| 97 | gcode_error = makerbot_driver.Gcode.UnrecognizedCommandError() |
| 98 | gcode_error.values['UnrecognizedCommand'] = codes['M'] |
| 99 | gcode_error.values['Suggestion'] = 'This gcode command is not valid for makerbot_driver.' |
| 100 | raise gcode_error |
| 101 | |
| 102 | # Not a G or M code, should we throw here? |
| 103 | else: |
| 104 | if len(codes) + len(flags) > 0: |
| 105 | self._log.error('{"event":"extraneous_code"}') |
| 106 | gcode_error = makerbot_driver.Gcode.ExtraneousCodeError() |
| 107 | raise gcode_error |
| 108 | |
| 109 | else: |
| 110 | pass |