Async
0.18.0
|
00001 00035 #ifndef SERIAL_INCLUDED 00036 #define SERIAL_INCLUDED 00037 00038 00039 /**************************************************************************** 00040 * 00041 * System Includes 00042 * 00043 ****************************************************************************/ 00044 00045 #include <sigc++/sigc++.h> 00046 #include <termios.h> 00047 #include <unistd.h> 00048 00049 #include <string> 00050 00051 00052 /**************************************************************************** 00053 * 00054 * Project Includes 00055 * 00056 ****************************************************************************/ 00057 00058 00059 00060 /**************************************************************************** 00061 * 00062 * Local Includes 00063 * 00064 ****************************************************************************/ 00065 00066 00067 00068 /**************************************************************************** 00069 * 00070 * Forward declarations 00071 * 00072 ****************************************************************************/ 00073 00074 00075 00076 /**************************************************************************** 00077 * 00078 * Namespace 00079 * 00080 ****************************************************************************/ 00081 00082 namespace Async 00083 { 00084 00085 00086 /**************************************************************************** 00087 * 00088 * Forward declarations of classes inside of the declared namespace 00089 * 00090 ****************************************************************************/ 00091 00092 class FdWatch; 00093 class SerialDevice; 00094 00095 00096 /**************************************************************************** 00097 * 00098 * Defines & typedefs 00099 * 00100 ****************************************************************************/ 00101 00102 00103 00104 /**************************************************************************** 00105 * 00106 * Exported Global Variables 00107 * 00108 ****************************************************************************/ 00109 00110 00111 00112 /**************************************************************************** 00113 * 00114 * Class definitions 00115 * 00116 ****************************************************************************/ 00117 00129 class Serial : public SigC::Object 00130 { 00131 public: 00135 typedef enum 00136 { 00137 PARITY_NONE, 00138 PARITY_EVEN, 00139 PARITY_ODD 00140 } Parity; 00141 00145 typedef enum 00146 { 00147 FLOW_NONE, 00148 FLOW_HW, 00149 FLOW_XONOFF 00150 } Flow; 00151 00155 typedef enum 00156 { 00157 PIN_NONE, 00158 PIN_RTS, 00159 PIN_DTR, 00160 PIN_CTS, 00161 PIN_DSR, 00162 PIN_DCD, 00163 PIN_RI 00164 } Pin; 00165 00169 static const int READ_BUFSIZE = 1024; 00170 00171 00181 explicit Serial(const std::string& serial_port); 00182 00186 ~Serial(void); 00187 00204 bool setParams(int speed, Parity parity, int bits, int stop_bits, 00205 Flow flow); 00206 00220 bool open(void); 00221 00233 bool close(void); 00234 00243 int write(const char *buf, size_t count) 00244 { 00245 return ::write(fd, buf, count); 00246 } 00247 00264 bool setCanonical(bool canonical); 00265 00276 bool stopInput(bool stop); 00277 00289 bool setPin(Pin pin, bool set); 00290 00302 bool getPin(Pin pin, bool &is_set); 00303 00314 SigC::Signal2<void, char*, int> charactersReceived; 00315 00316 00317 protected: 00318 00319 private: 00320 const std::string serial_port; 00321 bool canonical; 00322 00323 int fd; 00324 struct termios port_settings; 00325 SerialDevice *dev; 00326 00327 00328 }; /* class Serial */ 00329 00330 00331 } /* namespace */ 00332 00333 #endif /* SERIAL_INCLUDED */ 00334 00335 00336 00337 /* 00338 * This file has not been truncated 00339 */ 00340