/[H7]/branches/linux-serial/Serial.h
ViewVC logotype

Diff of /branches/linux-serial/Serial.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 47 by torben, Mon Feb 5 00:48:02 2007 UTC revision 76 by torben, Wed Jun 4 13:06:09 2008 UTC
# Line 9  Line 9 
9  #include <vector>  #include <vector>
10  #include <string>  #include <string>
11  #include <stdexcept>  #include <stdexcept>
 typedef std::vector<unsigned char> UCVector;  
12    
13  #ifndef _WINDOWS //  #ifndef _MSC_VER //
14  inline void Sleep(int x) { usleep(x*1000);}  inline void Sleep(int x) { usleep(x*1000);}
15  #include <termios.h>  #include <termios.h>
16  #endif  #endif
# Line 19  inline void Sleep(int x) { usleep(x*1000 Line 18  inline void Sleep(int x) { usleep(x*1000
18    
19  class CSerial  class CSerial
20  {  {
21  #ifdef _WINDOWS          
22    public: //public enumerations
23            enum Baudrate
24            {
25                    Baud300,
26                    Baud600,
27                    Baud1200,
28                    Baud2400,
29                    Baud4800,
30                    Baud9600,
31                    Baud19200,
32                    Baud38400,
33                    Baud57600,
34                    Baud115200
35            };
36    private: // member vars
37    #ifdef _MSC_VER
38          HANDLE mComport;          HANDLE mComport;
39          DCB mDcbRestore;          DCB mDcbRestore;
40  #else  #else
# Line 28  class CSerial Line 43  class CSerial
43  #endif  #endif
44                    
45          char* mPortstr;          char* mPortstr;
46          int mBitrate;          Baudrate mBitrate;
47          bool mIsopen;          bool mIsopen;
48    
49  public:  public: //public methods
50          CSerial();          CSerial();
51          CSerial(char* port, int bitrate);          CSerial(char* port, Baudrate bitrate);
52          ~CSerial(void);          virtual ~CSerial(void);
53    
54          void close();          void close();
55          void open(char* port, int bitrate);          void open(char* port, Baudrate bitrate);
56    
57          int readByte();          int readByte();
58          void writeByte(unsigned char out);          void writeByte(unsigned char out);
59    
60  #ifdef _WINDOWS          void writeBytes(unsigned char* buf, unsigned int len);
61            int readBytes(unsigned char* buf, unsigned int maxLen);
62    
63    #ifdef _MSC_VER
64          COMSTAT getComstat() const;          COMSTAT getComstat() const;
65  #endif  #endif
66          int bytesReady() const;          int bytesReady() const;
67          int outQueueSize() const;          int outQueueSize() const;
68          char* getPort() const {return mPortstr;}          char* getPort() const {return mPortstr;}
69          int getBitrate() const {return mBitrate;}          Baudrate getBitrate() const {return mBitrate;}
70    
71          bool isOpen() { return mIsopen; }          bool isOpen() { return mIsopen; }
72    
         //void writeBytes(UCVector out);  
         //UCVector readBytes(int maxcount);  
73  protected:  protected:
74                    
75          void printByte(char* description, unsigned char byte);          void printByte(char* description, unsigned char byte);
76  #ifdef _WINDOWS          int convertBaudrate(Baudrate rate);
77    
78    #ifdef _MSC_VER
79          void openWindows();          void openWindows();
80            int readBytesWindows(unsigned char*buf, unsigned int maxLen);
81            void writeBytesWindows(unsigned char* buf, unsigned int len);
82  #else  #else
83          void openLinux();          void openLinux();
84            int readBytesLinux(unsigned char* buf, unsigned int maxLen);
85            void writeBytesLinux(unsigned char* buf, unsigned int len);
86  #endif  #endif
87  };  };

Legend:
Removed from v.47  
changed lines
  Added in v.76

  ViewVC Help
Powered by ViewVC 1.1.20