libserial 0.6.0rc1

SerialStream.h

Go to the documentation of this file.
00001 /*
00002  * Time-stamp: <2008-10-30 16:30:11 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 <SerialStreamBuf.h>
00014 
00015 extern "C++" {
00016     namespace LibSerial {
00050         class SerialStream : public std::iostream {
00051         public:
00052             /* ------------------------------------------------------------
00053              * Public Static Members
00054              * ------------------------------------------------------------ */
00055 
00059 
00085             explicit SerialStream( const std::string fileName, 
00086                                    std::ios_base::openmode openMode =
00087                                    std::ios::in|std::ios::out) ;
00088 
00099             SerialStream( const std::string fileName,
00100                           const SerialStreamBuf::BaudRateEnum baudRate = SerialStreamBuf::DEFAULT_BAUD,
00101                           const SerialStreamBuf::CharSizeEnum charSize = SerialStreamBuf::DEFAULT_CHAR_SIZE,
00102                           const SerialStreamBuf::ParityEnum parityType = SerialStreamBuf::DEFAULT_PARITY,
00103                           const short numOfStopBits = SerialStreamBuf::DEFAULT_NO_OF_STOP_BITS,
00104                           const SerialStreamBuf::FlowControlEnum flowControlType = SerialStreamBuf::DEFAULT_FLOW_CONTROL ) ;
00105 
00111             explicit SerialStream() ;
00112       
00117             virtual ~SerialStream() ; 
00119 
00127             void Open( const std::string fileName, 
00128                        std::ios_base::openmode openMode = 
00129                        std::ios_base::in | std::ios_base::out) ;
00130 
00135             void Close() ;
00136 
00140             const bool IsOpen() const ;
00141 
00145             void SetBaudRate(SerialStreamBuf::BaudRateEnum baudRate ) ;
00146 
00158             const SerialStreamBuf::BaudRateEnum BaudRate() ;
00159 
00164             void SetCharSize(const SerialStreamBuf::CharSizeEnum charSize ) ;
00165 
00170             const SerialStreamBuf::CharSizeEnum CharSize() ;
00171 
00178             void SetNumOfStopBits(short numOfStopBits) ;
00179 
00184             const short NumOfStopBits() ; 
00185 
00191             void SetParity(const SerialStreamBuf::ParityEnum parityType) ;
00192 
00198             const SerialStreamBuf::ParityEnum Parity() ;
00199 
00203             void 
00204             SetFlowControl(const SerialStreamBuf::FlowControlEnum flowControlType) ;
00205 
00209             const SerialStreamBuf::FlowControlEnum FlowControl() ;
00210 
00214             const short SetVMin( short vtime ) ;
00215 
00216 
00222             const short VMin() ;
00223 
00227             const short SetVTime( short vtime ) ;
00228 
00234             const short VTime() ;
00235 
00237 
00241 
00243 
00244             /* ------------------------------------------------------------
00245              * Friends
00246              * ------------------------------------------------------------
00247              */
00248         protected:
00249             /* ------------------------------------------------------------
00250              * Protected Data Members
00251              * ------------------------------------------------------------
00252              */
00253             /* ------------------------------------------------------------
00254              * Protected Methods
00255              * ------------------------------------------------------------
00256              */
00257         private:
00258             /* ------------------------------------------------------------
00259              * Private Data Members
00260              * ------------------------------------------------------------
00261              */
00262             //
00263             // The copy constructor and the assignment operator are declared
00264             // but never defined. This allows the compiler to catch any
00265             // attempts to copy instances of this class.
00266             //
00267             SerialStream( const SerialStream& ) ;
00268             SerialStream& operator=( const SerialStream& ) ;
00269 
00274             SerialStreamBuf *mIOBuffer ;
00275 
00276             /* ----------------------------------------------------------------
00277              * Private Methods
00278              * ----------------------------------------------------------------
00279              */
00280             /* Set the serial port to ignore the modem status lines. If the
00281                specified boolean parameter is false then the meaning of
00282                this function is reversed i.e. the serial port will start
00283                using the modem status lines.
00284 
00285                @param ignore If true then the modem status lines will be
00286                ignored otherwise they will be used during the
00287                communication.
00288 
00289             */
00290             //void IgnoreModemStatusLines(bool ignore=true) ;
00291 
00292             /* Enable the serial port receiver. This will allow us to read
00293                data from the serial port.
00294        
00295                @param enable If true then the received will be
00296                enabled. Otherwise it will be disabled.
00297 
00298             */
00299             //void EnableReceiver(bool enable=true) ;
00300 
00301         } ; // class SerialStream
00302 
00303         inline
00304         SerialStream::SerialStream() : 
00305           std::iostream(0), mIOBuffer(0) {
00306             //
00307             // Close the stream
00308             //
00309             Close() ;
00310         }
00311 
00312         inline
00313         SerialStream::~SerialStream() {
00314             // 
00315             // If a SerialStreamBuf is associated with this SerialStream
00316             // then we need to destroy it here.
00317             //
00318             if( mIOBuffer ) {
00319                 delete mIOBuffer ;
00320             }
00321         }
00322 
00323         inline
00324         void 
00325         SerialStream::Close() {
00326             //
00327             // If a SerialStreamBuf is associated with the SerialStream then
00328             // destroy it.
00329             //
00330             if( mIOBuffer ) {
00331                 delete mIOBuffer ;
00332                 mIOBuffer = 0 ;
00333             }
00334         }
00335 
00336         inline
00337         const bool
00338         SerialStream::IsOpen() const {
00339             //
00340             // Checks to see if mIOBuffer is a null buffer, if not,
00341             // calls the is_open() function on this streams SerialStreamBuf,
00342             // mIOBuffer
00343             //
00344             if ( ! mIOBuffer ) {
00345                 return false ;
00346             }
00347             return mIOBuffer->is_open() ;
00348         }
00349 
00350     } // namespace LibSerial
00351 } // extern "C++"
00352 #endif // #ifndef _SerialStream_h_