SerialStream.h

Go to the documentation of this file.
00001 /*
00002  * Time-stamp: <04/05/05 15:25:22 pagey>
00003  *
00004  * $Id: SerialStream.h,v 1.10 2005/10/01 21:24:21 crayzeewulf Exp $
00005  *
00006  *
00007  */
00008 #ifndef _SerialStream_h_
00009 #define _SerialStream_h_
00010 
00011 #include <string>
00012 #include <fstream>
00013 #include <cassert>
00014 #include <SerialStreamBuf.h>
00015 
00016 extern "C++" {
00017     namespace LibSerial {
00051         class SerialStream : public std::iostream {
00052         public:
00056 
00058 
00059 
00063 
00065 
00066             /* ------------------------------------------------------------
00067              * Public Static Members
00068              * ------------------------------------------------------------ */
00072 
00074 
00078 
00080 
00084 
00110             explicit SerialStream( const std::string  filename, 
00111                                    std::ios_base::openmode mode =
00112                                    std::ios::in|std::ios::out) ;
00113 
00119             explicit SerialStream() ;
00120       
00125             virtual ~SerialStream() ; 
00127 
00135             void Open(const std::string filename, 
00136                       std::ios_base::openmode mode = 
00137                       std::ios_base::in | std::ios_base::out) ;
00138 
00143             void Close() ;
00144 
00148             const bool IsOpen() const ;
00149 
00153             void SetBaudRate(SerialStreamBuf::BaudRateEnum baud_rate) ;
00154 
00166             const SerialStreamBuf::BaudRateEnum BaudRate() ;
00167 
00172             void SetCharSize(const SerialStreamBuf::CharSizeEnum size) ;
00173 
00178             const SerialStreamBuf::CharSizeEnum CharSize() ;
00179 
00186             void SetNumOfStopBits(short stop_bits) ;
00187 
00192             const short NumOfStopBits() ; 
00193 
00199             void SetParity(const SerialStreamBuf::ParityEnum parity) ;
00200 
00206             const SerialStreamBuf::ParityEnum Parity() ;
00207 
00211             void 
00212             SetFlowControl(const SerialStreamBuf::FlowControlEnum flow_c) ;
00213 
00217             const SerialStreamBuf::FlowControlEnum FlowControl() ;
00218 
00222             const short SetVMin( short vtime ) ;
00223 
00229             const short VMin() ;
00230 
00234             const short SetVTime( short vtime ) ;
00235 
00241             const short VTime() ;
00242 
00244 
00248 
00250 
00251             /* ------------------------------------------------------------
00252              * Friends
00253              * ------------------------------------------------------------
00254              */
00255         protected:
00256             /* ------------------------------------------------------------
00257              * Protected Data Members
00258              * ------------------------------------------------------------
00259              */
00260             /* ------------------------------------------------------------
00261              * Protected Methods
00262              * ------------------------------------------------------------
00263              */
00264         private:
00265             /* ------------------------------------------------------------
00266              * Private Data Members
00267              * ------------------------------------------------------------
00268              */
00273             SerialStreamBuf *mIOBuffer ;
00274 
00275             /* ----------------------------------------------------------------
00276              * Private Methods
00277              * ----------------------------------------------------------------
00278              */
00279             /* Set the serial port to ignore the modem status lines. If the
00280                specified boolean parameter is false then the meaning of
00281                this function is reversed i.e. the serial port will start
00282                using the modem status lines.
00283 
00284                @param ignore If true then the modem status lines will be
00285                ignored otherwise they will be used during the
00286                communication.
00287 
00288             */
00289             //void IgnoreModemStatusLines(bool ignore=true) ;
00290 
00291             /* Enable the serial port receiver. This will allow us to read
00292                data from the serial port.
00293        
00294                @param enable If true then the received will be
00295                enabled. Otherwise it will be disabled.
00296 
00297             */
00298             //void EnableReceiver(bool enable=true) ;
00299 
00300         } ; // class SerialStream
00301 
00302         inline
00303         SerialStream::SerialStream() : 
00304           std::iostream(0), mIOBuffer(0) {
00305             //
00306             // Close the stream
00307             //
00308             Close() ;
00309         }
00310 
00311         inline
00312         SerialStream::~SerialStream() {
00313             // 
00314             // If a SerialStreamBuf is associated with this SerialStream
00315             // then we need to destroy it here.
00316             //
00317             if( mIOBuffer ) {
00318                 delete mIOBuffer ;
00319             }
00320         }
00321 
00322         inline
00323         void 
00324         SerialStream::Close() {
00325             //
00326             // If a SerialStreamBuf is associated with the SerialStream then
00327             // destroy it.
00328             //
00329             if( mIOBuffer ) {
00330                 delete mIOBuffer ;
00331                 mIOBuffer = 0 ;
00332             }
00333         }
00334 
00335         inline
00336         const bool
00337         SerialStream::IsOpen() const {
00338             //
00339             // Checks to see if mIOBuffer is a null buffer, if not,
00340             // calls the is_open() function on this streams SerialStreamBuf,
00341             // mIOBuffer
00342             //
00343             if ( ! mIOBuffer ) {
00344                 return false ;
00345             }
00346             return mIOBuffer->is_open() ;
00347         }
00348 
00349     } ; // namespace LibSerial
00350 } // extern "C++"
00351 #endif // #ifndef _SerialStream_h_

Generated on Tue Jan 22 17:27:35 2008 for libserial by  doxygen 1.5.4