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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user