/* * Serial.h & Serial.cpp - (C) 2007 by Torben H. Nielsen * * A wrapper class for communicating with a serial port */ #pragma once #include #include #include typedef std::vector UCVector; #ifndef _MSC_VER // inline void Sleep(int x) { usleep(x*1000);} #include #endif class CSerial { #ifdef _MSC_VER HANDLE mComport; DCB mDcbRestore; #else int mFiledescriptor; termios mOldtio; #endif char* mPortstr; int mBitrate; bool mIsopen; public: CSerial(); CSerial(char* port, int bitrate); virtual ~CSerial(void); void close(); void open(char* port, int bitrate); int readByte(); void writeByte(unsigned char out); #ifdef _MSC_VER COMSTAT getComstat() const; #endif int bytesReady() const; int outQueueSize() const; char* getPort() const {return mPortstr;} int 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 _MSC_VER void openWindows(); #else void openLinux(); #endif };