From a5def5cf92c96b286024a72cdf24c814530373ac Mon Sep 17 00:00:00 2001 From: Daniel Beer Date: Sat, 30 Jul 2011 01:23:08 +1200 Subject: [PATCH] win32: set comm timeouts when opening serial port. --- sport.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sport.c b/sport.c index cde62fb..9fb0a51 100644 --- a/sport.c +++ b/sport.c @@ -106,6 +106,7 @@ sport_t sport_open(const char *device, int rate, int flags) FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, 0); DCB params = {0}; + COMMTIMEOUTS timeouts = {0}; if (hs == INVALID_HANDLE_VALUE) return INVALID_HANDLE_VALUE; @@ -125,6 +126,12 @@ sport_t sport_open(const char *device, int rate, int flags) return INVALID_HANDLE_VALUE; } + timeouts.ReadIntervalTimeout = 50; + if (!SetCommTimeouts(hs, &timeouts)) { + CloseHandle(hs); + return INVALID_HANDLE_VALUE; + } + return hs; }