From 8ff2542fbce8bbcfc92385f9903603fff9cf6792 Mon Sep 17 00:00:00 2001 From: portersky <24420859+portersky@users.noreply.github.com> Date: Mon, 15 Jun 2026 00:17:19 +0200 Subject: [PATCH] fix: avoid DTR/RTS pulse on serial port open Previously SetCommState was called with fDtrControl and fRtsControl left at whatever GetCommState returned (often enabled), then EscapeCommFunction lowered DTR/RTS after the fact. This produced a brief low-high-low pulse on connect, which can reset USB-UART-connected devices. Set DTR_CONTROL_DISABLE and RTS_CONTROL_DISABLE directly in the DCB before the single SetCommState call, so the lines never get pulsed. --- celrs/platform/serial_win.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/celrs/platform/serial_win.c b/celrs/platform/serial_win.c index e9fcf09..082a29b 100644 --- a/celrs/platform/serial_win.c +++ b/celrs/platform/serial_win.c @@ -27,6 +27,13 @@ cel_serial_platform_handle cel_serial_platform_open(char const* path, int baud_r dcb.Parity = NOPARITY; dcb.StopBits = ONESTOPBIT; + /* Keep DTR/RTS low so the TX module is not reset on connect. Setting + * these in the same SetCommState call (rather than via a later + * EscapeCommFunction) avoids a brief DTR/RTS-high pulse if the port's + * existing DCB has them enabled. */ + dcb.fDtrControl = DTR_CONTROL_DISABLE; + dcb.fRtsControl = RTS_CONTROL_DISABLE; + if (!SetCommState(h, &dcb)) { CloseHandle(h); return CEL_SERIAL_PLATFORM_INVALID_HANDLE;