00001 /* 00002 * Time-stamp: <04/05/05 15:25:22 pagey> 00003 * 00004 * $Id: SerialStream.h,v 1.9 2005/09/05 14:19:55 wedesoft Exp $ 00005 * 00006 * 00007 */ 00008 #ifndef _SerialStream_h_ 00009 #define _SerialStream_h_ 00010 00011 #ifndef _std_string_INCLUDED_ 00012 # include <string> 00013 # define _std_string_INCLUDED_ 00014 #endif 00015 00016 #ifndef _std_fstream_INCLUDED_ 00017 # include <fstream> 00018 # define _std_string_INCLUDED_ 00019 #endif 00020 00021 #ifndef _std_cassert_INCLUDED_ 00022 # include <cassert> 00023 # define _std_cassert_INCLUDED_ 00024 #endif 00025 00026 #ifndef SerialStreamBuf_h 00027 # include <SerialStreamBuf.h> 00028 #endif 00029 00030 extern "C++" { 00031 namespace LibSerial { 00065 class SerialStream : public std::iostream { 00066 public: 00070 00072 00073 00077 00079 00080 /* ------------------------------------------------------------ 00081 * Public Static Members 00082 * ------------------------------------------------------------ */ 00086 00088 00092 00094 00098 00124 explicit SerialStream( const std::string filename, 00125 std::ios_base::openmode mode = 00126 std::ios::in|std::ios::out) ; 00127 00133 explicit SerialStream() ; 00134 00139 virtual ~SerialStream() ; 00141 00149 void Open(const std::string filename, 00150 std::ios_base::openmode mode = 00151 std::ios_base::in | std::ios_base::out) ; 00152 00157 void Close() ; 00158 00162 const bool IsOpen() const ; 00163 00167 void SetBaudRate(SerialStreamBuf::BaudRateEnum baud_rate) ; 00168 00180 const SerialStreamBuf::BaudRateEnum BaudRate() ; 00181 00186 void SetCharSize(const SerialStreamBuf::CharSizeEnum size) ; 00187 00192 const SerialStreamBuf::CharSizeEnum CharSize() ; 00193 00200 void SetNumOfStopBits(short stop_bits) ; 00201 00206 const short NumOfStopBits() ; 00207 00213 void SetParity(const SerialStreamBuf::ParityEnum parity) ; 00214 00220 const SerialStreamBuf::ParityEnum Parity() ; 00221 00225 void 00226 SetFlowControl(const SerialStreamBuf::FlowControlEnum flow_c) ; 00227 00231 const SerialStreamBuf::FlowControlEnum FlowControl() ; 00232 00236 const short SetVMin( short vtime ) ; 00237 00243 const short VMin() ; 00244 00248 const short SetVTime( short vtime ) ; 00249 00255 const short VTime() ; 00256 00258 00262 00264 00265 /* ------------------------------------------------------------ 00266 * Friends 00267 * ------------------------------------------------------------ 00268 */ 00269 protected: 00270 /* ------------------------------------------------------------ 00271 * Protected Data Members 00272 * ------------------------------------------------------------ 00273 */ 00274 /* ------------------------------------------------------------ 00275 * Protected Methods 00276 * ------------------------------------------------------------ 00277 */ 00278 private: 00279 /* ------------------------------------------------------------ 00280 * Private Data Members 00281 * ------------------------------------------------------------ 00282 */ 00287 SerialStreamBuf *mIOBuffer ; 00288 00289 /* ---------------------------------------------------------------- 00290 * Private Methods 00291 * ---------------------------------------------------------------- 00292 */ 00293 /* Set the serial port to ignore the modem status lines. If the 00294 specified boolean parameter is false then the meaning of 00295 this function is reversed i.e. the serial port will start 00296 using the modem status lines. 00297 00298 @param ignore If true then the modem status lines will be 00299 ignored otherwise they will be used during the 00300 communication. 00301 00302 */ 00303 //void IgnoreModemStatusLines(bool ignore=true) ; 00304 00305 /* Enable the serial port receiver. This will allow us to read 00306 data from the serial port. 00307 00308 @param enable If true then the received will be 00309 enabled. Otherwise it will be disabled. 00310 00311 */ 00312 //void EnableReceiver(bool enable=true) ; 00313 00314 } ; // class SerialStream 00315 00316 inline 00317 SerialStream::SerialStream() : 00318 std::iostream(0), mIOBuffer(0) { 00319 // 00320 // Close the stream 00321 // 00322 Close() ; 00323 } 00324 00325 inline 00326 SerialStream::~SerialStream() { 00327 // 00328 // If a SerialStreamBuf is associated with this SerialStream 00329 // then we need to destroy it here. 00330 // 00331 if( mIOBuffer ) { 00332 delete mIOBuffer ; 00333 } 00334 } 00335 00336 inline 00337 void 00338 SerialStream::Close() { 00339 // 00340 // If a SerialStreamBuf is associated with the SerialStream then 00341 // destroy it. 00342 // 00343 if( mIOBuffer ) { 00344 delete mIOBuffer ; 00345 mIOBuffer = 0 ; 00346 } 00347 } 00348 00349 inline 00350 const bool 00351 SerialStream::IsOpen() const { 00352 // 00353 // Checks to see if mIOBuffer is a null buffer, if not, 00354 // calls the is_open() function on this streams SerialStreamBuf, 00355 // mIOBuffer 00356 // 00357 if ( ! mIOBuffer ) { 00358 return false ; 00359 } 00360 return mIOBuffer->is_open() ; 00361 } 00362 00363 } ; // namespace LibSerial 00364 } // extern "C++" 00365 #endif // #ifndef _SerialStream_h_
1.4.2