--- branches/linux-serial/Serial.cpp 2007/02/05 01:10:50 48 +++ branches/linux-serial/Serial.cpp 2007/02/05 07:06:43 49 @@ -1,6 +1,4 @@ -#ifdef _WINDOWS -#include "StdAfx.h" -#else //linux +#ifndef _MSC_VER //linux #include #include @@ -10,6 +8,7 @@ #include #endif +#include "StdAfx.h" #include "Serial.h" #include @@ -21,13 +20,13 @@ #define _POSIX_SOURCE 1 /* POSIX compliant source */ #define BAUDRATE B9600 -#ifndef _WINDOWS // ugly hack, else will gcc not accept this constant in openLinux() +#ifndef _MSC_VER // ugly hack, else will gcc not accept this constant in openLinux() const int flags = O_RDWR | O_NOCTTY ; //| O_NONBLOCK; #endif std::string writeLastError() { -#ifdef _WINDOWS +#ifdef _MSC_VER LPVOID lpMsgBuf; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, @@ -57,7 +56,7 @@ mBitrate = bitrate; mIsopen = false; -#ifdef _WINDOWS +#ifdef _MSC_VER openWindows(); #else openLinux(); @@ -77,14 +76,14 @@ mPortstr = port; mBitrate = bitrate; -#ifdef _WINDOWS +#ifdef _MSC_VER openWindows(); #else openLinux(); #endif } -#ifdef _WINDOWS +#ifdef _MSC_VER void CSerial::openWindows() { mComport = CreateFile( mPortstr, GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); @@ -118,7 +117,7 @@ { std::string error = writeLastError(); CloseHandle(mComport); - throw std::exception( error ); + throw std::runtime_error( error ); } mIsopen = true; @@ -126,7 +125,7 @@ #endif -#ifndef _WINDOWS +#ifndef _MSC_VER void CSerial::openLinux() { termios newtio; @@ -166,7 +165,7 @@ { if (mIsopen) { -#ifdef _WINDOWS +#ifdef _MSC_VER while (getComstat().cbOutQue >0) Sleep(5); SetCommState(mComport,&mDcbRestore); @@ -188,7 +187,7 @@ if (!mIsopen) throw std::runtime_error("Port not opened"); -#ifdef _WINDOWS +#ifdef _MSC_VER ReadFile(mComport,&out,1,&size,0); if (size != 1) { @@ -218,7 +217,7 @@ if (!mIsopen) throw std::runtime_error("Port not opened"); -#ifdef _WINDOWS +#ifdef _MSC_VER while (getComstat().cbOutQue >0) Sleep(2); @@ -239,7 +238,7 @@ #endif } -#ifdef _WINDOWS +#ifdef _MSC_VER COMSTAT CSerial::getComstat() const { if (!mIsopen) @@ -254,7 +253,7 @@ int CSerial::bytesReady() const { -#ifdef _WINDOWS +#ifdef _MSC_VER return getComstat().cbInQue; #else return 0; @@ -263,7 +262,7 @@ int CSerial::outQueueSize() const { -#ifdef _WINDOWS +#ifdef _MSC_VER return getComstat().cbOutQue; #else return 0;