From e50df2c1a1e6d5e9d6b8e8a8bc8311c344ab2083 Mon Sep 17 00:00:00 2001 From: rrrlasse Date: Tue, 29 Sep 2020 14:24:14 +0200 Subject: [PATCH 1/2] Fix connecting to printer via USB If the baudrate was anything else than 115200, detection of baudrate could fail because readline() with a wrong baudrate would never return, even if timeouts were set. --- plugins/USBPrinting/AutoDetectBaudJob.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/USBPrinting/AutoDetectBaudJob.py b/plugins/USBPrinting/AutoDetectBaudJob.py index 04fe64baaa..52666427bc 100644 --- a/plugins/USBPrinting/AutoDetectBaudJob.py +++ b/plugins/USBPrinting/AutoDetectBaudJob.py @@ -71,7 +71,8 @@ class AutoDetectBaudJob(Job): timeout_time = time() + wait_response_timeout while timeout_time > time(): - line = serial.readline() + # If baudrate is wrong, then readline() might never return, even with timeouts set. Using read_until with size limit seems to fix this. + line = serial.read_until(size = 100) if b"ok" in line and b"T:" in line: successful_responses += 1 if successful_responses >= 1: From 50935fdedadf0ed3832b61644ac3f0ef383ac3ed Mon Sep 17 00:00:00 2001 From: Lasse Reinhold Date: Thu, 12 Nov 2020 08:41:19 +0100 Subject: [PATCH 2/2] Update plugins/USBPrinting/AutoDetectBaudJob.py Co-authored-by: StefanBruens --- plugins/USBPrinting/AutoDetectBaudJob.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/USBPrinting/AutoDetectBaudJob.py b/plugins/USBPrinting/AutoDetectBaudJob.py index 52666427bc..b5a294dcda 100644 --- a/plugins/USBPrinting/AutoDetectBaudJob.py +++ b/plugins/USBPrinting/AutoDetectBaudJob.py @@ -71,7 +71,9 @@ class AutoDetectBaudJob(Job): timeout_time = time() + wait_response_timeout while timeout_time > time(): - # If baudrate is wrong, then readline() might never return, even with timeouts set. Using read_until with size limit seems to fix this. + # If baudrate is wrong, then readline() might never + # return, even with timeouts set. Using read_until + # with size limit seems to fix this. line = serial.read_until(size = 100) if b"ok" in line and b"T:" in line: successful_responses += 1