libserial  0.6.0rc1
SerialStream.h
Go to the documentation of this file.
1 /*
2  * Time-stamp: <2008-10-30 16:30:11 pagey>
3  *
4  * $Id: SerialStream.h,v 1.10 2005-10-01 21:24:21 crayzeewulf Exp $
5  *
6  *
7  */
8 #ifndef _SerialStream_h_
9 #define _SerialStream_h_
10 
11 #include <string>
12 #include <fstream>
13 #include <SerialStreamBuf.h>
14 
15 extern "C++" {
16  namespace LibSerial {
50  class SerialStream : public std::iostream {
51  public:
52  /* ------------------------------------------------------------
53  * Public Static Members
54  * ------------------------------------------------------------ */
55 
59 
85  explicit SerialStream( const std::string fileName,
86  std::ios_base::openmode openMode =
87  std::ios::in|std::ios::out) ;
88 
99  SerialStream( const std::string fileName,
103  const short numOfStopBits = SerialStreamBuf::DEFAULT_NO_OF_STOP_BITS,
105 
111  explicit SerialStream() ;
112 
117  virtual ~SerialStream() ;
119 
127  void Open( const std::string fileName,
128  std::ios_base::openmode openMode =
129  std::ios_base::in | std::ios_base::out) ;
130 
135  void Close() ;
136 
140  const bool IsOpen() const ;
141 
146 
159 
164  void SetCharSize(const SerialStreamBuf::CharSizeEnum charSize ) ;
165 
171 
178  void SetNumOfStopBits(short numOfStopBits) ;
179 
184  const short NumOfStopBits() ;
185 
191  void SetParity(const SerialStreamBuf::ParityEnum parityType) ;
192 
199 
203  void
204  SetFlowControl(const SerialStreamBuf::FlowControlEnum flowControlType) ;
205 
210 
214  const short SetVMin( short vtime ) ;
215 
216 
222  const short VMin() ;
223 
227  const short SetVTime( short vtime ) ;
228 
234  const short VTime() ;
235 
237 
241 
243 
244  /* ------------------------------------------------------------
245  * Friends
246  * ------------------------------------------------------------
247  */
248  protected:
249  /* ------------------------------------------------------------
250  * Protected Data Members
251  * ------------------------------------------------------------
252  */
253  /* ------------------------------------------------------------
254  * Protected Methods
255  * ------------------------------------------------------------
256  */
257  private:
258  /* ------------------------------------------------------------
259  * Private Data Members
260  * ------------------------------------------------------------
261  */
262  //
263  // The copy constructor and the assignment operator are declared
264  // but never defined. This allows the compiler to catch any
265  // attempts to copy instances of this class.
266  //
267  SerialStream( const SerialStream& ) ;
268  SerialStream& operator=( const SerialStream& ) ;
269 
275 
276  /* ----------------------------------------------------------------
277  * Private Methods
278  * ----------------------------------------------------------------
279  */
280  /* Set the serial port to ignore the modem status lines. If the
281  specified boolean parameter is false then the meaning of
282  this function is reversed i.e. the serial port will start
283  using the modem status lines.
284 
285  @param ignore If true then the modem status lines will be
286  ignored otherwise they will be used during the
287  communication.
288 
289  */
290  //void IgnoreModemStatusLines(bool ignore=true) ;
291 
292  /* Enable the serial port receiver. This will allow us to read
293  data from the serial port.
294 
295  @param enable If true then the received will be
296  enabled. Otherwise it will be disabled.
297 
298  */
299  //void EnableReceiver(bool enable=true) ;
300 
301  } ; // class SerialStream
302 
303  inline
305  std::iostream(0), mIOBuffer(0) {
306  //
307  // Close the stream
308  //
309  Close() ;
310  }
311 
312  inline
314  //
315  // If a SerialStreamBuf is associated with this SerialStream
316  // then we need to destroy it here.
317  //
318  if( mIOBuffer ) {
319  delete mIOBuffer ;
320  }
321  }
322 
323  inline
324  void
326  //
327  // If a SerialStreamBuf is associated with the SerialStream then
328  // destroy it.
329  //
330  if( mIOBuffer ) {
331  delete mIOBuffer ;
332  mIOBuffer = 0 ;
333  }
334  }
335 
336  inline
337  const bool
339  //
340  // Checks to see if mIOBuffer is a null buffer, if not,
341  // calls the is_open() function on this streams SerialStreamBuf,
342  // mIOBuffer
343  //
344  if ( ! mIOBuffer ) {
345  return false ;
346  }
347  return mIOBuffer->is_open() ;
348  }
349 
350  } // namespace LibSerial
351 } // extern "C++"
352 #endif // #ifndef _SerialStream_h_