From 3bd9d11fc3ab9a374f8f408934e533f09aaaf105 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Fri, 17 May 2019 22:43:13 -0500 Subject: [PATCH] comm: Don't open twice on FreeBSD Originally introduced by PR #673 to fix reconnect issues on pyserial, OctoPrint will first open the serial port with PARITY_ODD then close it again and reopen with the desired PARITY_NONE. This works around issues likely sitting somewhere in the linux tty layer, at least on some distributions, that don't necessarily exist on other platforms. Stop doing the workaround on FreeBSD to start with, as this is the only platform I can effectively test. I suspect MacOS/Windows likely also don't need to do this. --- src/octoprint/util/comm.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index e83b9d703..97b3d360e 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -39,6 +39,7 @@ from octoprint.filemanager.destinations import FileDestinations from octoprint.util import get_exception_string, sanitize_ascii, filter_non_ascii, CountedEvent, RepeatedTimer, \ to_unicode, bom_aware_open, TypedQueue, PrependableQueue, TypeAlreadyInQueue, chunks, ResettableTimer, \ monotonic_time +from octoprint.util.platform import get_os try: import _winreg @@ -2613,20 +2614,25 @@ class MachineCom(object): self._log("Connecting to: %s" % port) serial_port_args = { - "port": str(port), "baudrate": baudrateList()[0] if baudrate == 0 else baudrate, "timeout": read_timeout, "write_timeout": 0, - "parity": serial.PARITY_ODD } if settings().getBoolean(["serial", "exclusive"]): serial_port_args["exclusive"] = True serial_obj = serial.Serial(**serial_port_args) + serial_obj.port = str(port) - serial_obj.close() - serial_obj.parity = serial.PARITY_NONE + # This may also not be applicable to other platforms, in which case + # this should probably get rewritten as a whitelist for the platforms + # that have issues here. + if get_os() != 'freebsd': + serial_obj.parity = serial.PARITY_ODD + serial_obj.open() + serial_obj.close() + serial_obj.parity = serial.PARITY_NONE serial_obj.open() return BufferedReadlineWrapper(serial_obj)