From 1abec205027bcecd7d69c0a37619e513de7c2440 Mon Sep 17 00:00:00 2001 From: Jerry Jacobs Date: Mon, 14 Jun 2021 18:22:58 +0200 Subject: [PATCH] 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 ] --- serialport.c | 9 +++++++++ 1 file changed, 9 insertions(+) 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; -- 2.11.4.GIT