ComPort.h

00001 // --------------------------------------------------------------------------
00002 #ifndef _COMPORT_H_
00003 #define _COMPORT_H_
00004 // --------------------------------------------------------------------------
00005 #include <termios.h>
00006 #include <fcntl.h>
00007 #include <sys/ioctl.h>
00008 #include <string>
00009 // --------------------------------------------------------------------------
00010 class ComPort
00011 {
00012 public:
00013     enum Speed
00014     {
00015         ComSpeed0=B0,
00016         ComSpeed50=B50,
00017         ComSpeed75=B75,
00018         ComSpeed110=B110,
00019         ComSpeed134=B134,
00020         ComSpeed150=B150,
00021         ComSpeed200=B200,
00022         ComSpeed300=B300,
00023         ComSpeed600=B600,
00024         ComSpeed1200=B1200,
00025         ComSpeed1800=B1800,
00026         ComSpeed2400=B2400,
00027         ComSpeed4800=B4800,
00028         ComSpeed9600=B9600,
00029         ComSpeed19200=B19200,
00030         ComSpeed38400=B38400,
00031         ComSpeed57600=B57600,
00032         ComSpeed115200=B115200,
00033         ComSpeed230400=B230400,
00034         ComSpeed460800=B460800,
00035         ComSpeed500000=B500000,
00036         ComSpeed576000=B576000,
00037         ComSpeed921600=B921600,
00038         ComSpeed1000000=B1000000,
00039         ComSpeed1152000=B1152000,
00040         ComSpeed1500000=B1500000,
00041         ComSpeed2000000=B2000000,
00042         ComSpeed2500000=B2500000,
00043         ComSpeed3000000=B3000000,
00044         ComSpeed3500000=B3500000,
00045         ComSpeed4000000=B4000000
00046     };
00047     enum Parity
00048     {
00049         Odd,
00050         Even,
00051         Space,
00052         Mark,
00053         NoParity
00054     };
00055     enum CharacterSize
00056     {
00057         CSize5=CS5,
00058         CSize6=CS6,
00059         CSize7=CS7,
00060         CSize8=CS8
00061     };
00062     enum StopBits
00063     {
00064         OneBit=1,
00065         OneAndHalfBits=2,
00066         TwoBits=3
00067     };
00068 
00069     ComPort( const std::string comDevice, bool nocreate=false );
00070     virtual ~ComPort();
00071     
00072     void setSpeed( Speed s );
00073     void setSpeed( std::string speed );
00074     inline Speed getSpeed(){ return speed; }
00075     
00076     static Speed getSpeed( const std::string s );
00077     static std::string getSpeed( Speed s );
00078     
00079     void setParity(Parity);
00080     void setCharacterSize(CharacterSize);
00081     void setStopBits(StopBits sBit);
00082     
00083     virtual void setTimeout(int timeout);
00084     void setWaiting(bool waiting);
00085     inline int getTimeout(){ return uTimeout*1000; } // msec
00086     
00087     virtual unsigned char receiveByte();
00088     virtual void sendByte(unsigned char x);
00089 
00090     virtual int receiveBlock(unsigned char*msg,int len);
00091     virtual int sendBlock(unsigned char*msg,int len);
00092     
00093     void setBlocking(bool blocking);
00094     
00095     virtual void cleanupChannel();
00096     virtual void reopen();
00097     
00098 protected:
00099     void openPort();
00100 
00101     static const int BufSize=8192;
00102     unsigned char buf[BufSize];
00103     int curSym;
00104     int bufLength;
00105     int fd;
00106     int uTimeout;
00107     bool waiting;
00108     Speed speed;
00109     std::string dev;
00110     
00111     virtual unsigned char m_receiveByte( bool wait );
00112     
00113 private:
00114     struct termios oldTermios;
00115 };
00116 // --------------------------------------------------------------------------
00117 #endif // _COMPORT_H_
00118 // --------------------------------------------------------------------------

Документация по UniSet. Последние изменения: Mon Dec 3 16:14:25 2012. Создано системой  doxygen 1.5.9