From 537942c9edb37ebfc88d8b06fd330e8492d36bee Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Tue, 17 Dec 2013 17:19:55 +0000 Subject: [PATCH] Windows: clear errors after port open. --- serialport.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/serialport.c b/serialport.c index db77080..e935464 100644 --- a/serialport.c +++ b/serialport.c @@ -608,8 +608,9 @@ enum sp_return sp_open(struct sp_port *port, enum sp_mode flags) DEBUG("Opening port %s", port->name); #ifdef _WIN32 - DWORD desired_access = 0, flags_and_attributes = 0; + DWORD desired_access = 0, flags_and_attributes = 0, errors; char *escaped_port_name; + COMSTAT status; /* Prefix port name with '\\.\' to work with ports above COM9. */ if (!(escaped_port_name = malloc(strlen(port->name + 5)))) @@ -727,6 +728,10 @@ enum sp_return sp_open(struct sp_port *port, enum sp_mode flags) data.term.c_cflag |= (CLOCAL | CREAD | HUPCL); #endif +#ifdef _WIN32 + ClearCommError(port->hdl, &errors, &status); +#endif + ret = set_config(port, &data, &config); if (ret < 0) {