--- branches/linux-serial/Serial.cpp 2007/02/04 23:11:02 46 +++ branches/linux-serial/Serial.cpp 2007/02/05 00:48:02 47 @@ -19,10 +19,10 @@ #include #define _POSIX_SOURCE 1 /* POSIX compliant source */ -#define BAUDRATE B38400 +#define BAUDRATE B9600 #ifndef _WINDOWS // ugly hack, else will gcc not accept this constant in openLinux() -const int flags = O_RDWR | O_NOCTTY | O_NONBLOCK; +const int flags = O_RDWR | O_NOCTTY ; //| O_NONBLOCK; #endif std::string writeLastError() @@ -148,7 +148,11 @@ newtio.c_lflag = 0; newtio.c_cc[VTIME] = 0; /* inter-character timer unused */ - newtio.c_cc[VMIN] = 1; /* blocking read until 1 chars received */ + newtio.c_cc[VMIN] = 0; /* blocking read until 1 chars received */ + + cfmakeraw(&newtio); + cfsetospeed(&newtio, BAUDRATE); + tcflush(mFiledescriptor, TCIFLUSH); tcsetattr(mFiledescriptor, TCSANOW, &newtio); @@ -177,7 +181,7 @@ } -unsigned char CSerial::readByte() +int CSerial::readByte() { unsigned char out; unsigned long size; @@ -194,8 +198,11 @@ } #else //linux readByte() size = read(mFiledescriptor, &out, 1); - if (size != 1) - throw std::runtime_error( writeLastError() ); + if (size != 1) + { + std::cout << writeLastError() << std::endl; + return -1; + } #endif printByte("Read", out); @@ -207,7 +214,7 @@ { unsigned long size; - //printByte("Write", out); + printByte("Write", out); if (!mIsopen) throw std::runtime_error("Port not opened"); @@ -223,7 +230,10 @@ throw std::exception(error.c_str()); } #else //linux writeByte() + //tcdrain(mFiledescriptor); size = write(mFiledescriptor,&out,1); + Sleep(50); + //tcdrain(mFiledescriptor); if (size != 1) throw std::runtime_error(writeLastError() ); #endif