From a59baab49cc833bba309020d62b1def3d40b340a Mon Sep 17 00:00:00 2001 From: Daniil Tatianin <99danilt@gmail.com> Date: Mon, 28 Sep 2026 01:50:58 +0300 Subject: [PATCH] Open the display serial port in exclusive mode Nothing prevented two instances of the system monitor from opening the same serial port, e.g. when using "Save and run" from the configuration window while the system monitor is already running. Both instances then send commands to the display at the same time: the interleaved data corrupts the display (torn images), and a Turing 3.5" (rev. A) ends up rebooting and disconnecting from USB again and again. Open the port with pyserial exclusive=True. On Linux and macOS, it takes a flock() on the port so that a second instance cannot open it: it fails through the existing retry logic instead of corrupting the display. On Windows the option is ignored, COM ports are already opened in exclusive mode by the OS. --- library/lcd/lcd_comm.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/lcd/lcd_comm.py b/library/lcd/lcd_comm.py index 0e6f90b6..0b175c05 100644 --- a/library/lcd/lcd_comm.py +++ b/library/lcd/lcd_comm.py @@ -120,7 +120,8 @@ def openSerial(self): logger.debug(f"Static COM port: {com_port}") try: - self.lcd_serial = serial.Serial(com_port, 115200, timeout=1, rtscts=True) + # Exclusive lock: a second instance must not interleave commands with this one (corrupts the display) + self.lcd_serial = serial.Serial(com_port, 115200, timeout=1, rtscts=True, exclusive=True) return except Exception as e: logger.warning(