/[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

trunk/PIC/Testprogram/Serial.h revision 38 by torben, Thu Feb 1 10:03:52 2007 UTC branches/linux-serial/Serial.h revision 77 by torben, Wed Jun 4 13:08:30 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          HANDLE mComport;          
22          DCB mDcbRestore;  public: //public enumerations
23          CString mPortstr;          enum Baudrate
24          int mBitrate;          {
25          bool mIsopen;                  Baud300,
26                    Baud600,
27                    Baud1200,
28                    Baud2400,
29                    Baud4800,
30                    Baud9600,
31                    Baud19200,
32                    Baud38400,
33                    Baud57600,
34                    Baud115200
35            };
36    
37  protected:  public: //public methods
         void printByte(char* description, unsigned char byte);  
 public:  
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          unsigned char readByte();          int readByte();
46          void writeByte(unsigned char out);          void writeByte(unsigned char out);
47    
48            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
54          int bytesReady() const;          int bytesReady() const;
55          int outQueueSize() const;          int outQueueSize() const;
56          CString 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          void open();          
63            void printByte(char* description, unsigned char byte);
64            int convertBaudrate(Baudrate rate);
65    
66    #ifdef _MSC_VER
67            void openWindows();
68            int readBytesWindows(unsigned char*buf, unsigned int maxLen);
69            void writeBytesWindows(unsigned char* buf, unsigned int len);
70    #else
71            void openLinux();
72            int readBytesLinux(unsigned char* buf, unsigned int maxLen);
73            void writeBytesLinux(unsigned char* buf, unsigned int len);
74    #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.38  
changed lines
  Added in v.77

  ViewVC Help
Powered by ViewVC 1.1.20