/[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 77 by torben, Wed Jun 4 13:08:30 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  {  {
 #ifdef _WINDOWS  
         HANDLE mComport;  
         DCB mDcbRestore;  
 #else  
         int mFiledescriptor;  
         termios mOldtio;  
 #endif  
21                    
22          char* mPortstr;  public: //public enumerations
23          int mBitrate;          enum Baudrate
24          bool mIsopen;          {
25                    Baud300,
26                    Baud600,
27                    Baud1200,
28                    Baud2400,
29                    Baud4800,
30                    Baud9600,
31                    Baud19200,
32                    Baud38400,
33                    Baud57600,
34                    Baud115200
35            };
36    
37  public:  public: //public methods
38          CSerial();          CSerial();
39          CSerial(char* port, int bitrate);          CSerial(char* port, Baudrate bitrate);
40          ~CSerial(void);          virtual ~CSerial(void);
41    
42          void close();          void close();
43          void open(char* port, int bitrate);          void open(char* port, Baudrate bitrate);
44    
45          int readByte();          int readByte();
46          void writeByte(unsigned char out);          void writeByte(unsigned char out);
47    
48  #ifdef _WINDOWS          void writeBytes(unsigned char* buf, unsigned int len);
49            int readBytes(unsigned char* buf, unsigned int maxLen);
50    
51    #ifdef _MSC_VER
52          COMSTAT getComstat() const;          COMSTAT getComstat() const;
53  #endif  #endif
54          int bytesReady() const;          int bytesReady() const;
55          int outQueueSize() const;          int outQueueSize() const;
56          char* getPort() const {return mPortstr;}          char* getPort() const {return mPortstr;}
57          int getBitrate() const {return mBitrate;}          Baudrate getBitrate() const {return mBitrate;}
58    
59          bool isOpen() { return mIsopen; }          bool isOpen() { return mIsopen; }
60    
         //void writeBytes(UCVector out);  
         //UCVector readBytes(int maxcount);  
61  protected:  protected:
62                    
63          void printByte(char* description, unsigned char byte);          void printByte(char* description, unsigned char byte);
64  #ifdef _WINDOWS          int convertBaudrate(Baudrate rate);
65    
66    #ifdef _MSC_VER
67          void openWindows();          void openWindows();
68            int readBytesWindows(unsigned char*buf, unsigned int maxLen);
69            void writeBytesWindows(unsigned char* buf, unsigned int len);
70  #else  #else
71          void openLinux();          void openLinux();
72            int readBytesLinux(unsigned char* buf, unsigned int maxLen);
73            void writeBytesLinux(unsigned char* buf, unsigned int len);
74  #endif  #endif
75    
76    
77    private: // member vars
78    #ifdef _MSC_VER
79            HANDLE mComport;
80            DCB mDcbRestore;
81    #else
82            int mFiledescriptor;
83            termios mOldtio;
84    #endif
85            
86            char* mPortstr;
87            Baudrate mBitrate;
88            bool mIsopen;
89  };  };

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

  ViewVC Help
Powered by ViewVC 1.1.20