From: Jerry Jacobs Date: Mon, 14 Jun 2021 16:22:58 +0000 (+0200) Subject: Apply a default baudrate when the OS does not provide one. X-Git-Tag: libserialport-0.1.2~13 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=1abec205027bcecd7d69c0a37619e513de7c2440;p=libserialport.git Apply a default baudrate when the OS does not provide one. Handle the situation when the OS does not provide a baudrate in the code path which opens the serial port. See bug #1632 and PR #6 for details. https://sigrok.org/bugzilla/show_bug.cgi?id=1632 https://github.com/sigrokproject/libserialport/pull/6 This resolves bug #1632. [ gsi: adjust comment style, rephrase comment and commit message ] --- diff --git a/serialport.c b/serialport.c index d088398..e6097ee 100644 --- a/serialport.c +++ b/serialport.c @@ -590,6 +590,15 @@ SP_API enum sp_return sp_open(struct sp_port *port, enum sp_mode flags) RETURN_CODEVAL(ret); } + /* + * Assume a default baudrate if the OS does not provide one. + * Cannot assign -1 here since Windows holds the baudrate in + * the DCB and does not configure the rate individually. + */ + if (config.baudrate == 0) { + config.baudrate = 9600; + } + /* Set sane port settings. */ #ifdef _WIN32 data.dcb.fBinary = TRUE;