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

Legend:
Removed from v.44  
changed lines
  Added in v.54

  ViewVC Help
Powered by ViewVC 1.1.20