serial
1.1.0
Cross-platform, serial port library written in C++
|
00001 00038 #ifndef SERIAL_IMPL_UNIX_H 00039 #define SERIAL_IMPL_UNIX_H 00040 00041 #include "serial/serial.h" 00042 00043 #include <pthread.h> 00044 00045 namespace serial { 00046 00047 using std::string; 00048 using std::invalid_argument; 00049 00050 using serial::SerialExecption; 00051 using serial::IOException; 00052 00053 class serial::Serial::SerialImpl { 00054 public: 00055 SerialImpl (const string &port, 00056 unsigned long baudrate, 00057 bytesize_t bytesize, 00058 parity_t parity, 00059 stopbits_t stopbits, 00060 flowcontrol_t flowcontrol); 00061 00062 virtual ~SerialImpl (); 00063 00064 void 00065 open (); 00066 00067 void 00068 close (); 00069 00070 bool 00071 isOpen () const; 00072 00073 size_t 00074 available (); 00075 00076 size_t 00077 read (uint8_t *buf, size_t size = 1); 00078 00079 size_t 00080 write (const uint8_t *data, size_t length); 00081 00082 void 00083 flush (); 00084 00085 void 00086 flushInput (); 00087 00088 void 00089 flushOutput (); 00090 00091 void 00092 sendBreak (int duration); 00093 00094 void 00095 setBreak (bool level); 00096 00097 void 00098 setRTS (bool level); 00099 00100 void 00101 setDTR (bool level); 00102 00103 bool 00104 waitForChange (); 00105 00106 bool 00107 getCTS (); 00108 00109 bool 00110 getDSR (); 00111 00112 bool 00113 getRI (); 00114 00115 bool 00116 getCD (); 00117 00118 void 00119 setPort (const string &port); 00120 00121 string 00122 getPort () const; 00123 00124 void 00125 setTimeout (Timeout &timeout); 00126 00127 Timeout 00128 getTimeout () const; 00129 00130 void 00131 setBaudrate (unsigned long baudrate); 00132 00133 unsigned long 00134 getBaudrate () const; 00135 00136 void 00137 setBytesize (bytesize_t bytesize); 00138 00139 bytesize_t 00140 getBytesize () const; 00141 00142 void 00143 setParity (parity_t parity); 00144 00145 parity_t 00146 getParity () const; 00147 00148 void 00149 setStopbits (stopbits_t stopbits); 00150 00151 stopbits_t 00152 getStopbits () const; 00153 00154 void 00155 setFlowcontrol (flowcontrol_t flowcontrol); 00156 00157 flowcontrol_t 00158 getFlowcontrol () const; 00159 00160 void 00161 readLock (); 00162 00163 void 00164 readUnlock (); 00165 00166 void 00167 writeLock (); 00168 00169 void 00170 writeUnlock (); 00171 00172 protected: 00173 void reconfigurePort (); 00174 00175 private: 00176 string port_; // Path to the file descriptor 00177 int fd_; // The current file descriptor 00178 00179 bool is_open_; 00180 bool xonxoff_; 00181 bool rtscts_; 00182 00183 Timeout timeout_; // Timeout for read operations 00184 unsigned long baudrate_; // Baudrate 00185 00186 parity_t parity_; // Parity 00187 bytesize_t bytesize_; // Size of the bytes 00188 stopbits_t stopbits_; // Stop Bits 00189 flowcontrol_t flowcontrol_; // Flow Control 00190 00191 // Mutex used to lock the read functions 00192 pthread_mutex_t read_mutex; 00193 // Mutex used to lock the write functions 00194 pthread_mutex_t write_mutex; 00195 }; 00196 00197 } 00198 00199 #endif // SERIAL_IMPL_UNIX_H