From 79f44a4b9e5bec66024bd03e48c98bc933377286 Mon Sep 17 00:00:00 2001 From: Micke Prag Date: Wed, 9 Sep 2009 17:37:21 +0000 Subject: [PATCH] Fixes #54 where telldus-core hangs if no response is received from TellStick (Windows and Mac OS X). --- telldus-core/driver/libtelldus-core/win/Device.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/telldus-core/driver/libtelldus-core/win/Device.cpp b/telldus-core/driver/libtelldus-core/win/Device.cpp index 80e279c8..d8d915bd 100644 --- a/telldus-core/driver/libtelldus-core/win/Device.cpp +++ b/telldus-core/driver/libtelldus-core/win/Device.cpp @@ -29,6 +29,7 @@ int Device::send(const std::string &strMessage){ ftStatus = FT_Open(intDongleIndex, &fthHandle); int intBaudRate = 4800; //always 4800 ftStatus = FT_SetBaudRate(fthHandle, intBaudRate); + FT_SetTimeouts(fthHandle,5000,0); ULONG bytesWritten, bytesRead; char *tempMessage = (char *)malloc(sizeof(char) * (strMessage.size()+1)); @@ -40,16 +41,23 @@ int Device::send(const std::string &strMessage){ while(c) { ftStatus = FT_Read(fthHandle,&in,1,&bytesRead); if (ftStatus == FT_OK) { - if (in == '\n') { + if (bytesRead == 1) { + if (in == '\n') { + break; + } + } else { //Timeout c = false; } - } else { - //Timeout or error + } else { //Error c = false; } } ftStatus = FT_Close(fthHandle); + + if (!c) { + return TELLSTICK_ERROR_NOT_FOUND; + } } catch(...){ throw;