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.
This commit is contained in:
2026-06-15 00:17:19 +02:00
parent df09615d3f
commit 8ff2542fbc
+7
View File
@@ -27,6 +27,13 @@ cel_serial_platform_handle cel_serial_platform_open(char const* path, int baud_r
dcb.Parity = NOPARITY; dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT; 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)) { if (!SetCommState(h, &dcb)) {
CloseHandle(h); CloseHandle(h);
return CEL_SERIAL_PLATFORM_INVALID_HANDLE; return CEL_SERIAL_PLATFORM_INVALID_HANDLE;