--- branches/linux-serial/Serial.h 2007/02/04 21:22:44 44 +++ branches/linux-serial/Serial.h 2007/02/05 10:10:18 54 @@ -7,45 +7,64 @@ #pragma once #include +#include +#include typedef std::vector UCVector; -#ifndef _WINDOWS // +#ifndef _MSC_VER // inline void Sleep(int x) { usleep(x*1000);} +#include #endif 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 int mFiledescriptor; + termios mOldtio; #endif char* mPortstr; - int mBitrate; + Baudrate mBitrate; bool mIsopen; - //void printByte(char* description, unsigned char byte); -public: +public: //public methods CSerial(); - CSerial(char* port, int bitrate); - ~CSerial(void); + CSerial(char* port, Baudrate bitrate); + virtual ~CSerial(void); void close(); - void open(char* port, int bitrate); + void open(char* port, Baudrate bitrate); - unsigned char readByte(); + int readByte(); void writeByte(unsigned char out); -#ifdef _WINDOWS +#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; } @@ -53,7 +72,9 @@ //UCVector readBytes(int maxcount); protected: -#ifdef _WINDOWS + void printByte(char* description, unsigned char byte); + int convertBaudrate(Baudrate rate); +#ifdef _MSC_VER void openWindows(); #else void openLinux();