From 9b13eb8a6c1ab763586ab7a0c6fd9fd3e64901ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 29 Jul 2016 00:13:03 +0200 Subject: [PATCH] Support serial hook handlers to not return written bytes --- src/octoprint/util/comm.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 8fb0bf23..24b9c838 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -2036,11 +2036,21 @@ class MachineCom(object): old_written = written try: - written += self._serial.write(to_send) + result = self._serial.write(to_send) + if result is None or not isinstance(result, int): + # probably some plugin not returning the written bytes, assuming all of them + written += len(cmd) + else: + written += result except serial.SerialTimeoutException: self._log("Serial timeout while writing to serial port, trying again.") try: - written += self._serial.write(to_send) + result = self._serial.write(to_send) + if result is None or not isinstance(result, int): + # probably some plugin not returning the written bytes, assuming all of them + written += len(cmd) + else: + written += result except: if not self._connection_closing: self._logger.exception("Unexpected error while writing to serial port")