SerialPort.h

Go to the documentation of this file.
00001 #ifndef __SerialPort_included
00002         #define __SerialPort_included
00003 #endif
00004 #ifndef __termios_included
00005         #define __termios_included
00006         #include <termios.h> /* POSIX terminal control definitions */
00007 #endif
00008 #ifndef __fcntl_included
00009         #define __fcntl_included
00010         #include <fcntl.h>      /* File control definitions */
00011 #endif
00012 #ifndef __stdio_included
00013         #define __stdio_included
00014         #include <stdio.h>      /* Standard input/output definitions */
00015 #endif
00016 #ifndef __unistd_included
00017         #define __unistd_included
00018         #include <unistd.h>     /* UNIX standard function definitions */
00019 #endif
00020 
00021 // Referenced from http://www.easysw.com/~mike/serial/serial.html
00022 
00023 namespace SerialPorts {
00024         
00025         enum BaudRateEnum {
00026         BAUD_50    = B50,
00027         BAUD_75    = B75,
00028         BAUD_110   = B110,
00029         BAUD_134   = B134,
00030         BAUD_150   = B150,
00031         BAUD_200   = B200,
00032         BAUD_300   = B300,
00033         BAUD_600   = B600,
00034         BAUD_1200  = B1200,
00035         BAUD_1800  = B1800,
00036         BAUD_2400  = B2400,
00037         BAUD_4800  = B4800,
00038         BAUD_9600  = B9600,
00039         BAUD_19200 = B19200,
00040         BAUD_38400 = B38400,
00041         BAUD_57600 = B57600,
00042         BAUD_115200 = B115200,
00043         BAUD_ERR,
00044         };
00045         
00046         enum CharSizeEnum {
00047         CHAR_SIZE_5 = CS5,
00048         CHAR_SIZE_6 = CS6,
00049         CHAR_SIZE_7 = CS7,
00050         CHAR_SIZE_8 = CS8,
00051         CHAR_SIZE_ERR
00052     };
00053 
00054         enum ParityEnum {
00055         PARITY_EVEN,
00056         PARITY_ODD,
00057         PARITY_NONE,
00058         PARITY_ERR
00059     };      
00060 
00061  
00062         enum FlowControlEnum {
00063         FLOW_CONTROL_HARD,
00064         FLOW_CONTROL_SOFT,
00065         FLOW_CONTROL_NONE,
00066         FLOW_CONTROL_ERR
00067     };
00068     
00069     const BaudRateEnum DEFAULT_BAUDRATE = BAUD_9600;
00070     const CharSizeEnum DEFAULT_CHARSIZE = CHAR_SIZE_8;
00071     const ParityEnum DEFAULT_PARITY = PARITY_NONE;
00072     const FlowControlEnum DEFAULT_FLOWCONTROL = FLOW_CONTROL_NONE;
00073     
00074         static const char CTRL_Q = 0x11 ;
00075         static const char CTRL_S = 0x13 ;
00076     
00077     
00078     class SerialPort {
00079         private:
00080                 int fd;
00081                 int state;
00082                 int stopbits;
00083                 enum BaudRateEnum baud;
00084                 enum CharSizeEnum charsize;
00085                 enum ParityEnum parity;
00086                 enum FlowControlEnum flowctrl;
00087                 
00088         public:
00089                 SerialPort(){
00090                                 this->state = -1; this->fd = -1;
00091                         }
00092                 ~SerialPort(){};
00093                 int open(char * devicename);
00094                 int close();
00095                 int status();
00096                 int write( char * data, int lenght);
00097                 char readChar();
00098                 char * readBytes(int bytes);
00099                 int dataWaiting();
00100                 
00101                 enum BaudRateEnum setBaudRate( enum BaudRateEnum bps);
00102                 //enum BaudRateEnum getBaudRate();
00103                 
00104                 enum CharSizeEnum setCharSize( enum CharSizeEnum charsize);
00105                 enum ParityEnum setParity( enum ParityEnum parity);
00106                 int setStopBits(int stopbits);
00107                 enum FlowControlEnum setFlowControl( enum FlowControlEnum flowctrl);
00108                                 
00109     }; //class SerialPort
00110 }; //namespace SerialPorts

Generated on Tue May 31 20:21:08 2005 for sendsms by  doxygen 1.4.2