fix: guard UART window creation with try-except to prevent silent crash

On Windows the UartMonitorWindow could crash instantly without any
error message. Added try-except around window creation in _read_serial
so errors are logged instead of silently killing the window.

Also added empty port guard before attempting to open.
This commit is contained in:
2026-06-11 18:23:40 +08:00
parent f330f8c276
commit 906f787748
+13 -5
View File
@@ -1585,12 +1585,20 @@ class MainWindow(ctk.CTk):
def _read_serial(self) -> None: def _read_serial(self) -> None:
"""Open the UART Monitor window.""" """Open the UART Monitor window."""
port = self._port_var.get() port = self._port_var.get().strip()
if not port:
self._log_message(" ✗ No serial port selected")
return
baudrate = self._config.serial_baudrate if self._config else 115200 baudrate = self._config.serial_baudrate if self._config else 115200
self._uart_window = UartMonitorWindow( try:
self, port=port, baudrate=baudrate, self._uart_window = UartMonitorWindow(
on_log=self._log_message, self, port=port, baudrate=baudrate,
) on_log=self._log_message,
)
except Exception as e:
self._log_message(f" ✗ Failed to open UART window: {e}")
import traceback
self._log_message(traceback.format_exc())
def _test_serial_version(self) -> None: def _test_serial_version(self) -> None:
"""Test serial port by sending 'ver()' command and parsing response.""" """Test serial port by sending 'ver()' command and parsing response."""