Fixes #54 where telldus-core hangs if no response is received from TellStick (Windows and Mac OS X).

This commit is contained in:
Micke Prag 2009-09-09 17:37:21 +00:00
parent c45c901f5d
commit 79f44a4b9e

View file

@ -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;