From 258b824ff894d9d2fb6b211b82a84efc875a6fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 17 Feb 2015 21:53:45 +0100 Subject: [PATCH] self._printer in plugins now allows direct access to the transport object (serial instance in most cases) --- src/octoprint/printer/__init__.py | 15 +++++++++++++++ src/octoprint/util/comm.py | 3 +++ 2 files changed, 18 insertions(+) diff --git a/src/octoprint/printer/__init__.py b/src/octoprint/printer/__init__.py index e537e279..3a9aca5e 100644 --- a/src/octoprint/printer/__init__.py +++ b/src/octoprint/printer/__init__.py @@ -213,6 +213,21 @@ class Printer(): self._printerProfileManager.deselect() eventManager().fire(Events.DISCONNECTED) + def getTransport(self): + """ + Returns the communication layer's transport object, if a connection is currently established. + + Note that this doesn't have to necessarily be a :class:`serial.Serial` instance, it might also be something + different, so take care to do instance checks before attempting to access any properties or methods. + + :return: the communication layer's transport object + """ + + if self._comm is None: + return None + + return self._comm.getTransport() + def command(self, command): """ Sends a single gcode command to the printer. diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index f13c3f76..caacd08e 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -340,6 +340,9 @@ class MachineCom(object): def getConnection(self): return self._port, self._baudrate + def getTransport(self): + return self._serial + ##~~ external interface def close(self, isError = False):