From ae712d9878a78dc1eb22913fef48b3b4100d9cfd Mon Sep 17 00:00:00 2001 From: Mark Walker Date: Mon, 30 Mar 2015 17:58:35 -0700 Subject: [PATCH] Add GPX as a serial port filter The idea is to have GPX translate between g-codes and x3g. GPX already does a pretty good job for output gcode intended for print instructions, that is the gcode output by slicers. It has some minimal support for talking directly to the printer and receiving data back from the printer. What I'm hoping to add is translation of printer output to responses a generic Marlin printer might produce. For now, I'm focused on the I/O that OctoPrint uses. --- src/octoprint/filemanager/__init__.py | 3 ++- src/octoprint/printer/profile.py | 1 + src/octoprint/util/comm.py | 29 +++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/octoprint/filemanager/__init__.py b/src/octoprint/filemanager/__init__.py index 068caa2ee..28365a4c7 100644 --- a/src/octoprint/filemanager/__init__.py +++ b/src/octoprint/filemanager/__init__.py @@ -23,7 +23,8 @@ extensions = dict( ), # extensions for printable machine code machinecode=dict( - gcode=["gcode", "gco", "g"] + gcode=["gcode", "gco", "g"], + x3g=["x3g", "s3g"] ) ) diff --git a/src/octoprint/printer/profile.py b/src/octoprint/printer/profile.py index 547e81df9..a4499a2ae 100644 --- a/src/octoprint/printer/profile.py +++ b/src/octoprint/printer/profile.py @@ -291,6 +291,7 @@ class PrinterProfileManager(object): import yaml with open(path) as f: profile = yaml.safe_load(f) + profile = dict_merge(self._load_default(), profile) profile = self._ensure_valid_profile(profile) if not profile: self._logger.warn("Invalid profile: %s" % path) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index ddc31d2c3..58fc2e5f3 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -173,6 +173,7 @@ class MachineCom(object): self._gcode_hooks = self._pluginManager.get_hooks("octoprint.comm.protocol.gcode") self._printer_action_hooks = self._pluginManager.get_hooks("octoprint.comm.protocol.action") self._gcodescript_hooks = self._pluginManager.get_hooks("octoprint.comm.protocol.scripts") + self._serial_hooks = self._pluginManager.get_hooks("octoprint.comm.protocol.serial") # SD status data self._sdAvailable = False @@ -1166,8 +1167,7 @@ class MachineCom(object): else: return False - def _openSerial(self): - if self._port == 'AUTO': + def detectPort(self, close): self._changeState(self.STATE_DETECT_SERIAL) programmer = stk500v2.Stk500v2() self._log("Serial port list: %s" % (str(serialList()))) @@ -1188,6 +1188,31 @@ class MachineCom(object): self._errorValue = 'Failed to autodetect serial port.' self._changeState(self.STATE_ERROR) eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) + return None + if (close): + self._serial.close() + self._serial = None + return p + + def _openSerial(self): + self._logger.info("_openSerial") + for hook in self._serial_hooks: + _serialT = None + try: + serialT = self._serial_hooks[hook](self, self._port, self._baudrate, settings().getFloat(["serial", "timeout", "connection"])) + except Exception as e: + self._errorValue = get_exception_string() + self._changeState(self.STATE_ERROR) + eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) + return False + if serialT is not None: + self._changeState(self.STATE_OPEN_SERIAL); + self._serial = serialT + return True + # first hook to succeed wins, but any can pass on to the next + + if self._port is None or self._port == 'AUTO': + if self._detectPort(False) is None: return False elif self._port == 'VIRTUAL': self._changeState(self.STATE_OPEN_SERIAL)