libserial  0.6.0rc3
SerialStreamBuf.h
Go to the documentation of this file.
1 /*
2  * Time-stamp: <2008-11-15 13:06:59 pagey>
3  *
4  * $Id: SerialStreamBuf.h,v 1.9 2005-10-17 00:19:12 crayzeewulf Exp $
5  *
6  *
7  */
8 #ifndef _SerialStreamBuf_h_
9 #define _SerialStreamBuf_h_
10 
11 #include <SerialPort.h>
12 #include <boost/scoped_ptr.hpp>
13 #include <streambuf>
14 #include <string>
15 
16 extern "C++"
17 {
18  namespace LibSerial
19  {
38  class SerialStreamBuf : public std::streambuf
39  {
40  public:
41  /*
42  * -----------------------------------------------------------------
43  * Enumerations.
44  * -----------------------------------------------------------------
45  */
60  {
79 #ifdef __linux__
80  BAUD_460800 = SerialPort::BAUD_460800,
81  BAUD_500000 = SerialPort::BAUD_500000,
82  BAUD_576000 = SerialPort::BAUD_576000,
83  BAUD_921600 = SerialPort::BAUD_921600,
84  BAUD_1000000 = SerialPort::BAUD_1000000,
85  BAUD_1152000 = SerialPort::BAUD_1152000,
86  BAUD_1500000 = SerialPort::BAUD_1500000,
87  BAUD_2000000 = SerialPort::BAUD_2000000,
88  BAUD_2500000 = SerialPort::BAUD_2500000,
89  BAUD_3000000 = SerialPort::BAUD_3000000,
90  BAUD_3500000 = SerialPort::BAUD_3500000,
91  BAUD_4000000 = SerialPort::BAUD_4000000,
92 #endif
95  } ;
96 
107  {
114  } ;
115 
125  {
131  } ;
132 
142  {
148  } ;
149 
150  /* ------------------------------------------------------------
151  * Public Static Members
152  * ------------------------------------------------------------
153  */
160  static const BaudRateEnum DEFAULT_BAUD ;
161 
170 
177  static const short DEFAULT_NO_OF_STOP_BITS ;
178 
185  static const ParityEnum DEFAULT_PARITY ;
186 
194 
203  static const short DEFAULT_VMIN ;
204 
213  static const short DEFAULT_VTIME ;
214 
215  /* -----------------------------------------------------------------
216  * Constructors and Destructor
217  * -----------------------------------------------------------------
218  */
222  SerialStreamBuf() ;
223 
227  ~SerialStreamBuf() ;
228 
229  /* -----------------------------------------------------------------
230  * Other Public Methods
231  * -----------------------------------------------------------------
232  */
238  bool is_open() const ;
239 
287  SerialStreamBuf* open( const std::string filename,
288  std::ios_base::openmode mode =
289  std::ios_base::in | std::ios_base::out ) ;
290 
312 
317  int SetParametersToDefault() ;
318 
324  const BaudRateEnum SetBaudRate(const BaudRateEnum baudRate ) ;
325 
331  const BaudRateEnum BaudRate() const ;
332 
338  const CharSizeEnum SetCharSize(const CharSizeEnum charSize) ;
339 
344  const CharSizeEnum CharSize() const ;
345 
353  short SetNumOfStopBits(short numOfStopBits) ;
354 
360  short NumOfStopBits() const ;
361 
367  const ParityEnum SetParity(const ParityEnum parityType) ;
368 
374  const ParityEnum Parity() const ;
375 
379  const FlowControlEnum SetFlowControl(const FlowControlEnum flowControlType) ;
380 
384  const FlowControlEnum FlowControl() const ;
385 
390  const short SetVMin( short vtime ) ;
391 
396  const short VMin() const;
397 
402  const short SetVTime( short vtime ) ;
403 
408  const short VTime() const;
409 
410  /* -----------------------------------------------------------------
411  * Operators
412  * -----------------------------------------------------------------
413  */
414 
415  /* ------------------------------------------------------------
416  * Friends
417  * ------------------------------------------------------------
418  */
419  protected:
420  /* ------------------------------------------------------------
421  * Protected Data Members
422  * ------------------------------------------------------------
423  */
428  static const char CTRL_Q = 0x11 ;
429 
434  static const char CTRL_S = 0x13 ;
435  /* ------------------------------------------------------------
436  * Protected Methods
437  * ------------------------------------------------------------
438  */
452  virtual std::streambuf* setbuf( char_type*,
453  std::streamsize ) ;
454 
461  virtual std::streamsize xsgetn( char_type* s,
462  std::streamsize n ) ;
463 
473  virtual std::streamsize showmanyc();
474 
482  virtual int_type underflow() ;
483 
492  virtual int_type uflow() ;
493 
500  virtual int_type pbackfail(int_type c = traits_type::eof()) ;
501 
508  virtual std::streamsize xsputn( const char_type* s,
509  std::streamsize n ) ;
510 
516  virtual int_type overflow(int_type c) ;
517 
518  private:
519  /* ------------------------------------------------------------
520  * Private Data Members
521  * ------------------------------------------------------------
522  */
523  //
524  // The copy constructor and the assignment operator are
525  // declared private but never defined. This allows the
526  // compiler to catch attempts to copy instances of this
527  // class.
528  //
529  SerialStreamBuf( const SerialStreamBuf& ) ;
531 
532  class Implementation ;
533  boost::scoped_ptr<Implementation> mImpl ;
534  } ; // class SerialStreamBuf
535  } // namespace LibSerial
536 } // extern "C++"
537 #endif // #ifndef _SerialStreamBuf_h_
FlowControlEnum
The values of the flow control settings for a serial port.
static const short DEFAULT_VTIME
The default character buffer timing.
const short VTime() const
Get the current timeout value for non-canonical reads in deciseconds.
static const ParityEnum DEFAULT_PARITY
The default parity setting.
const BaudRateEnum BaudRate() const
Return the current baud rate of the serial port.
const ParityEnum Parity() const
Get the current parity setting for the serial port.
static const short DEFAULT_VMIN
The default character buffer size.
CharSizeEnum
The allowed values of character sizes that can be used during the serial communication.
virtual std::streamsize xsputn(const char_type *s, std::streamsize n)
Writes upto n characters from the character sequence at s to the serial port associated with the buff...
~SerialStreamBuf()
The destructor.
const short VMin() const
Get the VMIN value for the device.
short SetNumOfStopBits(short numOfStopBits)
Set the number of stop bits used during serial communication.
virtual std::streamsize showmanyc()
Check, wether input is available on the port.
SerialStreamBuf * close()
If is_open() == false, returns a null pointer.
static const CharSizeEnum DEFAULT_CHAR_SIZE
The default value of the character size used during the serial communication.
const short SetVTime(short vtime)
Set character buffer timeout in 10ths of a second.
static const FlowControlEnum DEFAULT_FLOW_CONTROL
The default flow control setting.
static const char CTRL_Q
Character used to signal that I/O can start while using software flow control with the serial port...
const BaudRateEnum SetBaudRate(const BaudRateEnum baudRate)
If is_open() != true, return -1.
SerialStreamBuf * open(const std::string filename, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out)
If is_open() != false, returns a null pointer.
BaudRateEnum
The baud rates currently supported by the SUS-2 general terminal interface specification.
7 bit characters.
Definition: SerialPort.h:99
const ParityEnum SetParity(const ParityEnum parityType)
Set the parity for serial communication.
const CharSizeEnum SetCharSize(const CharSizeEnum charSize)
Set the character size to be used during serial communication.
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.
int SetParametersToDefault()
Initialize the serial communication parameters to their default values.
No parity i.e. parity checking disabled.
Definition: SerialPort.h:113
const short SetVMin(short vtime)
Set the minimum number of characters for non-canonical reads.
This is the streambuf subclass used by SerialStream.
5 bit characters.
Definition: SerialPort.h:97
const FlowControlEnum FlowControl() const
Return the current flow control setting.
8 bit characters.
Definition: SerialPort.h:100
6 bit characters.
Definition: SerialPort.h:98
virtual std::streamsize xsgetn(char_type *s, std::streamsize n)
Reads upto n characters from the serial port and returns them through the character array located at ...
virtual std::streambuf * setbuf(char_type *, std::streamsize)
Performs an operation that is defined separately for each class derived from streambuf.
SerialStreamBuf & operator=(const SerialStreamBuf &)
virtual int_type underflow()
Reads and returns the next character from the associated serial port if one otherwise returns traits:...
short NumOfStopBits() const
Get the number of stop bits being used during serial communication.
static const short DEFAULT_NO_OF_STOP_BITS
The default number of stop bits used.
boost::scoped_ptr< Implementation > mImpl
static const BaudRateEnum DEFAULT_BAUD
The default value of the baud rate of the serial port.
const CharSizeEnum CharSize() const
Return the character size currently being used for serial communication.
virtual int_type pbackfail(int_type c=traits_type::eof())
This function is called when a putback of a character fails.
static const char CTRL_S
Character used to signal that I/O should stop while using software flow control with the serial port...
const FlowControlEnum SetFlowControl(const FlowControlEnum flowControlType)
Use the specified flow control.
virtual int_type overflow(int_type c)
Writes the specified character to the associated serial port.
SerialStreamBuf()
The default constructor.
virtual int_type uflow()
Reads and returns the next character from the associated serial port if one otherwise returns traits:...