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_
FlowControlEnum
The values of the flow control settings for a serial port.
static const ParityEnum DEFAULT_PARITY
The default parity setting.
CharSizeEnum
The allowed values of character sizes that can be used during the serial communication.
void SetBaudRate(SerialStreamBuf::BaudRateEnum baudRate)
Set the baud rate for serial communications.
const short NumOfStopBits()
Get the number of stop bits being used during serial communication.
void Open(const std::string fileName, std::ios_base::openmode openMode=std::ios_base::in|std::ios_base::out)
Open the serial port associated with the specified filename, and the specified mode, mode.
const SerialStreamBuf::BaudRateEnum BaudRate()
Get the current baud rate being used for serial communication.
const short VTime()
Get current timing of character buffer in 10th of a second.
const SerialStreamBuf::FlowControlEnum FlowControl()
Return the current flow control setting.
static const CharSizeEnum DEFAULT_CHAR_SIZE
The default value of the character size used during the serial communication.
static const FlowControlEnum DEFAULT_FLOW_CONTROL
The default flow control setting.
SerialStream & operator=(const SerialStream &)
void SetNumOfStopBits(short numOfStopBits)
Set the number of stop bits used during serial communication.
void SetParity(const SerialStreamBuf::ParityEnum parityType)
Set the parity for serial communication.
const short SetVMin(short vtime)
Set character buffer size.
const SerialStreamBuf::CharSizeEnum CharSize()
Get the character size being used for serial communication.
SerialStreamBuf * mIOBuffer
The SerialStreamBuf object that will be used by the stream to communicate with the serial port...
Definition: SerialStream.h:274
BaudRateEnum
The baud rates currently supported by the SUS-2 general terminal interface specification.
const short SetVTime(short vtime)
Set character buffer timing in 10th of a second.
SerialStream()
Create a new SerialStream object but do not open it.
Definition: SerialStream.h:304
bool is_open() const
Returns true if a previous call to open() succeeded (returned a non-null value) and there has been no...
ParityEnum
The allowed values of the parity associated with the serial port communications.
const SerialStreamBuf::ParityEnum Parity()
Get the current parity setting for the serial port.
A stream class for accessing serial ports on POSIX operating systems.
Definition: SerialStream.h:50
This is the streambuf subclass used by SerialStream.
const bool IsOpen() const
Returns true if the Stream is in a good open state, false otherwise.
Definition: SerialStream.h:338
const short VMin()
Get current size of character buffer.
void Close()
Close the serial port.
Definition: SerialStream.h:325
void SetCharSize(const SerialStreamBuf::CharSizeEnum charSize)
Set the character size associated with the serial port.
static const short DEFAULT_NO_OF_STOP_BITS
The default number of stop bits used.
virtual ~SerialStream()
The destructor.
Definition: SerialStream.h:313
static const BaudRateEnum DEFAULT_BAUD
The default value of the baud rate of the serial port.
void SetFlowControl(const SerialStreamBuf::FlowControlEnum flowControlType)
Use the specified flow control.