--- branches/linux-serial/Serial.h 2007/02/05 01:10:50 48 +++ branches/linux-serial/Serial.h 2008/06/04 13:06:09 76 @@ -9,9 +9,8 @@ #include #include #include -typedef std::vector UCVector; -#ifndef _WINDOWS // +#ifndef _MSC_VER // inline void Sleep(int x) { usleep(x*1000);} #include #endif @@ -19,7 +18,23 @@ class CSerial { -#ifdef _WINDOWS + +public: //public enumerations + enum Baudrate + { + Baud300, + Baud600, + Baud1200, + Baud2400, + Baud4800, + Baud9600, + Baud19200, + Baud38400, + Baud57600, + Baud115200 + }; +private: // member vars +#ifdef _MSC_VER HANDLE mComport; DCB mDcbRestore; #else @@ -28,38 +43,45 @@ #endif char* mPortstr; - int mBitrate; + Baudrate mBitrate; bool mIsopen; -public: +public: //public methods CSerial(); - CSerial(char* port, int bitrate); + CSerial(char* port, Baudrate bitrate); virtual ~CSerial(void); void close(); - void open(char* port, int bitrate); + void open(char* port, Baudrate bitrate); int readByte(); void writeByte(unsigned char out); -#ifdef _WINDOWS + void writeBytes(unsigned char* buf, unsigned int len); + int readBytes(unsigned char* buf, unsigned int maxLen); + +#ifdef _MSC_VER COMSTAT getComstat() const; #endif int bytesReady() const; int outQueueSize() const; char* getPort() const {return mPortstr;} - int getBitrate() const {return mBitrate;} + Baudrate getBitrate() const {return mBitrate;} bool isOpen() { return mIsopen; } - //void writeBytes(UCVector out); - //UCVector readBytes(int maxcount); protected: void printByte(char* description, unsigned char byte); -#ifdef _WINDOWS + int convertBaudrate(Baudrate rate); + +#ifdef _MSC_VER void openWindows(); + int readBytesWindows(unsigned char*buf, unsigned int maxLen); + void writeBytesWindows(unsigned char* buf, unsigned int len); #else void openLinux(); + int readBytesLinux(unsigned char* buf, unsigned int maxLen); + void writeBytesLinux(unsigned char* buf, unsigned int len); #endif };