/[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 43 by torben, Sun Feb 4 20:11:41 2007 UTC revision 76 by torben, Wed Jun 4 13:06:09 2008 UTC
# Line 7  Line 7 
7  #pragma once  #pragma once
8    
9  #include <vector>  #include <vector>
10    #include <string>
11    #include <stdexcept>
12    
13    #ifndef _MSC_VER //
14    inline void Sleep(int x) { usleep(x*1000);}
15    #include <termios.h>
16    #endif
17    
 typedef std::vector<unsigned char> UCVector;  
18    
19  class CSerial  class CSerial
20  {  {
21            
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          CString mPortstr;  #else
41          int mBitrate;          int mFiledescriptor;
42            termios mOldtio;
43    #endif
44            
45            char* mPortstr;
46            Baudrate mBitrate;
47          bool mIsopen;          bool mIsopen;
48    
49  protected:  public: //public methods
         void printByte(char* description, unsigned char byte);  
 public:  
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          unsigned char readByte();          int readByte();
58          void writeByte(unsigned char out);          void writeByte(unsigned char out);
59    
60            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
66          int bytesReady() const;          int bytesReady() const;
67          int outQueueSize() const;          int outQueueSize() const;
68          CString 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          void open();          
75            void printByte(char* description, unsigned char byte);
76            int convertBaudrate(Baudrate rate);
77    
78    #ifdef _MSC_VER
79            void openWindows();
80            int readBytesWindows(unsigned char*buf, unsigned int maxLen);
81            void writeBytesWindows(unsigned char* buf, unsigned int len);
82    #else
83            void openLinux();
84            int readBytesLinux(unsigned char* buf, unsigned int maxLen);
85            void writeBytesLinux(unsigned char* buf, unsigned int len);
86    #endif
87  };  };

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

  ViewVC Help
Powered by ViewVC 1.1.20