---
name: "LibSerial_SerialStreamBuf"
section: "3"
platform: "linux"
package: "libserial-doc"
version: "0.6.0~rc2+svn122-4"
release: "Debian 10 (Buster)"
platforms: ["linux"]
url: "https://new.carta.tech/LibSerial_SerialStreamBuf"
---

# LibSerial\_SerialStreamBuf(3)

This is the streambuf subclass used by SerialStream.

## NAME

LibSerial::SerialStreamBuf - This is the streambuf subclass used by **SerialStream**.

## SYNOPSIS

`#include <SerialStreamBuf.h>`

Inherits streambuf.

### Public Types

enum **BaudRateEnum** { **BAUD\_50** = SerialPort::BAUD\_50, **BAUD\_75** = SerialPort::BAUD\_75, **BAUD\_110** = SerialPort::BAUD\_110, **BAUD\_134** = SerialPort::BAUD\_134, **BAUD\_150** = SerialPort::BAUD\_150, **BAUD\_200** = SerialPort::BAUD\_200, **BAUD\_300** = SerialPort::BAUD\_300, **BAUD\_600** = SerialPort::BAUD\_600, **BAUD\_1200** = SerialPort::BAUD\_1200, **BAUD\_1800** = SerialPort::BAUD\_1800, **BAUD\_2400** = SerialPort::BAUD\_2400, **BAUD\_4800** = SerialPort::BAUD\_4800, **BAUD\_9600** = SerialPort::BAUD\_9600, **BAUD\_19200** = SerialPort::BAUD\_19200, **BAUD\_38400** = SerialPort::BAUD\_38400, **BAUD\_57600** = SerialPort::BAUD\_57600, **BAUD\_115200** = SerialPort::BAUD\_115200, **BAUD\_230400** = SerialPort::BAUD\_230400, **BAUD\_DEFAULT** = SerialPort::BAUD\_DEFAULT, **BAUD\_INVALID** = -1 }\
 *The baud rates currently supported by the SUS-2 general terminal interface specification.*  enum **CharSizeEnum** { **CHAR\_SIZE\_5** = SerialPort::CHAR\_SIZE\_5, **CHAR\_SIZE\_6** = SerialPort::CHAR\_SIZE\_6, **CHAR\_SIZE\_7** = SerialPort::CHAR\_SIZE\_7, **CHAR\_SIZE\_8** = SerialPort::CHAR\_SIZE\_8, **CHAR\_SIZE\_DEFAULT** = SerialPort::CHAR\_SIZE\_DEFAULT, **CHAR\_SIZE\_INVALID** }\
 *The allowed values of character sizes that can be used during the serial communication.*  enum **ParityEnum** { **PARITY\_EVEN** = SerialPort::PARITY\_EVEN, **PARITY\_ODD** = SerialPort::PARITY\_ODD, **PARITY\_NONE** = SerialPort::PARITY\_NONE, **PARITY\_DEFAULT** = SerialPort::PARITY\_DEFAULT, **PARITY\_INVALID** }\
 *The allowed values of the parity associated with the serial port communications.*  enum **FlowControlEnum** { **FLOW\_CONTROL\_HARD** = SerialPort::FLOW\_CONTROL\_HARD, **FLOW\_CONTROL\_SOFT** = SerialPort::FLOW\_CONTROL\_SOFT, **FLOW\_CONTROL\_NONE** = SerialPort::FLOW\_CONTROL\_NONE, **FLOW\_CONTROL\_DEFAULT** = SerialPort::FLOW\_CONTROL\_DEFAULT, **FLOW\_CONTROL\_INVALID** }\
 *The values of the flow control settings for a serial port.*

### Public Member Functions

**SerialStreamBuf** ()\
 *The default constructor.*  **~SerialStreamBuf** ()\
 *The destructor.*  bool **is\_open** () const \
 *Returns true if a previous call to* **open()** *succeeded (returned a non-null value) and there has been no intervening call to close.*  **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.*  **SerialStreamBuf** \* **close** ()\
 *If* **is\_open()** *== false, returns a null pointer.*  int **SetParametersToDefault** ()\
 *Initialize the serial communication parameters to their default values.*  const **BaudRateEnum** **SetBaudRate** (const **BaudRateEnum** baudRate)\
 *If* **is\_open()** *!= true, return -1.*  const **BaudRateEnum** **BaudRate** () const \
 *Return the current baud rate of the serial port.*  const **CharSizeEnum** **SetCharSize** (const **CharSizeEnum** charSize)\
 *Set the character size to be used during serial communication.*  const **CharSizeEnum** **CharSize** () const \
 *Return the character size currently being used for serial communication.*  short **SetNumOfStopBits** (short numOfStopBits)\
 *Set the number of stop bits used during serial communication.*  short **NumOfStopBits** () const \
 *Get the number of stop bits being used during serial communication.*  const **ParityEnum** **SetParity** (const **ParityEnum** parityType)\
 *Set the parity for serial communication.*  const **ParityEnum** **Parity** () const \
 *Get the current parity setting for the serial port.*  const **FlowControlEnum** **SetFlowControl** (const **FlowControlEnum** flowControlType)\
 *Use the specified flow control.*  const **FlowControlEnum** **FlowControl** () const \
 *Return the current flow control setting.*  const short **SetVMin** (short vtime)\
 *Set the minimum number of characters for non-canonical reads.*  const short **VMin** () const \
 *Get the VMIN value for the device.*  const short **SetVTime** (short vtime)\
 *Set character buffer timeout in 10ths of a second.*  const short **VTime** () const \
 *Get the current timeout value for non-canonical reads in deciseconds.*

### Static Public Attributes

static const **BaudRateEnum** **DEFAULT\_BAUD**\
 *The default value of the baud rate of the serial port.*  static const **CharSizeEnum** **DEFAULT\_CHAR\_SIZE**\
 *The default value of the character size used during the serial communication.*  static const short **DEFAULT\_NO\_OF\_STOP\_BITS**\
 *The default number of stop bits used.*  static const **ParityEnum** **DEFAULT\_PARITY**\
 *The default parity setting.*  static const **FlowControlEnum** **DEFAULT\_FLOW\_CONTROL**\
 *The default flow control setting.*  static const short **DEFAULT\_VMIN**\
 *The default character buffer size.*  static const short **DEFAULT\_VTIME**\
 *The default character buffer timing.*

### Protected Member Functions

virtual std::streambuf \* **setbuf** (char\_type \*, std::streamsize)\
 *Performs an operation that is defined separately for each class derived from streambuf.*  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 s.*  virtual std::streamsize **showmanyc** ()\
 *Check, wether input is available on the port.*  virtual int\_type **underflow** ()\
 *Reads and returns the next character from the associated serial port if one otherwise returns traits::eof().*  virtual int\_type **uflow** ()\
 *Reads and returns the next character from the associated serial port if one otherwise returns traits::eof().*  virtual int\_type **pbackfail** (int\_type c=traits\_type::eof())\
 *This function is called when a putback of a character fails.*  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 buffer.*  virtual int\_type **overflow** (int\_type c)\
 *Writes the specified character to the associated serial port.*

### Static Protected Attributes

static const char **CTRL\_Q** = 0x11\
 *Character used to signal that I/O can start while using software flow control with the serial port.*  static const char **CTRL\_S** = 0x13\
 *Character used to signal that I/O should stop while using software flow control with the serial port.*

### Private Member Functions

**SerialStreamBuf** (const **SerialStreamBuf** &)\
 **SerialStreamBuf** & **operator=** (const **SerialStreamBuf** &)\

### Private Attributes

boost::scoped\_ptr\< Implementation \> **mImpl**\

## Detailed Description

This is the streambuf subclass used by **SerialStream**.

This subclass takes care of opening the serial port file in the required modes and providing the corresponding file descriptor to **SerialStream** so that various parameters associated with the serial port can be set. Several features of this streambuf class resemble those of std::filebuf, however this class it not made a subclass of filebuf because we need access to the file descriptor associated with the serial port and the standard filebuf does not provide access to it.

At present, this class uses unbuffered I/O and all calls to **setbuf()** will be ignored.

**Author:**

**Author**

crayzeewulf

`Manish P. Pagey`

**Version:**

**Id**

**SerialStreamBuf.h**,v 1.9 2005-10-17 00:19:12 crayzeewulf Exp

Definition at line 38 of file SerialStreamBuf.h.

## Member Enumeration Documentation

### enum LibSerial::SerialStreamBuf::BaudRateEnum

The baud rates currently supported by the SUS-2 general terminal interface specification. Note that B0 is not supported because it is not really a baud rate (it causes the modem to hang up i.e. drop DTR). Use the **close()** method instead.

**Deprecated**

This enumeration will be removed in revision 0.7.x of libserial. It is here for backward compatibility with 0.5.x releases. Please use the corresponding enumeration from **SerialPort** class instead.

**Enumerator**

- *BAUD\_50*

  - *BAUD\_75*

  - *BAUD\_110*

  - *BAUD\_134*

  - *BAUD\_150*

  - *BAUD\_200*

  - *BAUD\_300*

  - *BAUD\_600*

  - *BAUD\_1200*

  - *BAUD\_1800*

  - *BAUD\_2400*

  - *BAUD\_4800*

  - *BAUD\_9600*

  - *BAUD\_19200*

  - *BAUD\_38400*

  - *BAUD\_57600*

  - *BAUD\_115200*

  - *BAUD\_230400*

  - *BAUD\_DEFAULT*

  - *BAUD\_INVALID*

  *Definition at line 59 of file SerialStreamBuf.h.*

### enum LibSerial::SerialStreamBuf::CharSizeEnum

*The allowed values of character sizes that can be used during the serial communication.*

**Deprecated**

*This enumeration is deprecated. It will be removed in version 0.7.0. It is here for backward compatibility with version 0.5.x. Please use* **SerialPort::CharacterSize** *instead.*

**Enumerator**

- *CHAR\_SIZE\_5*

  - *CHAR\_SIZE\_6*

  - *CHAR\_SIZE\_7*

  - *CHAR\_SIZE\_8*

  - *CHAR\_SIZE\_DEFAULT*

  - *CHAR\_SIZE\_INVALID*

  *Definition at line 106 of file SerialStreamBuf.h.*

### enum LibSerial::SerialStreamBuf::FlowControlEnum

*The values of the flow control settings for a serial port.*

**Deprecated**

*This enumeration has been deprecated and will be removed in version 0.7.0. Please use* **SerialPort::FlowControl** *instead.*

**Enumerator**

- *FLOW\_CONTROL\_HARD*

  - *FLOW\_CONTROL\_SOFT*

  - *FLOW\_CONTROL\_NONE*

  - *FLOW\_CONTROL\_DEFAULT*

  - *FLOW\_CONTROL\_INVALID*

  *Invalid flow control setting.*

*Definition at line 141 of file SerialStreamBuf.h.*

### enum LibSerial::SerialStreamBuf::ParityEnum

*The allowed values of the parity associated with the serial port communications.*

**Deprecated**

*This enumeration is deprecated and will be removed in version 0.7.0. Please use* **SerialPort::Parity** *instead.*

**Enumerator**

- *PARITY\_EVEN*

  - *PARITY\_ODD*

  - *PARITY\_NONE*

  - *PARITY\_DEFAULT*

  - *PARITY\_INVALID*

  *Invalid parity value.*

*Definition at line 124 of file SerialStreamBuf.h.*

## Constructor & Destructor Documentation

### LibSerial::SerialStreamBuf::SerialStreamBuf ()

*The default constructor.*

### LibSerial::SerialStreamBuf::~SerialStreamBuf ()

*The destructor.*

### LibSerial::SerialStreamBuf::SerialStreamBuf (const SerialStreamBuf &)` [private]`

## Member Function Documentation

### const BaudRateEnum LibSerial::SerialStreamBuf::BaudRate () const

*Return the current baud rate of the serial port. If the baud rate is not set to a valid value then it returns BAUD\_INVALID.*

### const CharSizeEnum LibSerial::SerialStreamBuf::CharSize () const

*Return the character size currently being used for serial communication.*

### SerialStreamBuf\* LibSerial::SerialStreamBuf::close ()

*If* **is\_open()** *== false, returns a null pointer. If a put area exists, calls overflow(EOF) to flush characters. Finally it closes the file by calling* `std::close(mFileDescriptor)` *where mFileDescriptor is the value returned by the last call to* **open()***.*

*For the implementation of the corresponding function in class filebuf, if the last virtual member function called on* `*this` *(between underflow, overflow,* `seekoff`*, and* `seekpos`*) was overflow then it calls* `a_codecvt.unshift` *(possible several times) to determine a termination sequence, inserts those characters and calls overflow(EOF) again. However,* **this is not implemented here yet***.*

**Postcondition***:* **is\_open()** *==* `false`

**Returns:**

`this on success, a null pointer otherwise. `

### const FlowControlEnum LibSerial::SerialStreamBuf::FlowControl () const

`Return the current flow control setting. `

### bool LibSerial::SerialStreamBuf::is\_open () const

`Returns true if a previous call to `**open()**` succeeded (returned a non-null value) and there has been no intervening call to close. `

### short LibSerial::SerialStreamBuf::NumOfStopBits () const

`Get the number of stop bits being used during serial communication. `

**Returns:**

`The number of stop bits. `

### SerialStreamBuf\* LibSerial::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. Otherwise, initializes the streambuf as required. It then opens a file, if possible, whose name is given as the string filename using the system call std::open(filename.c_str(), flags). The value of parameter flags is obtained from the value of the parameter mode. At present, only ios_base::in, ios_base::out, and (ios_base::in|ios_base::out) make sense for a serial port and hence all other settings result in the call to fail. The value of flags is obtained as: `\

`flags = u_flags | O_NOCTTY `\

`where u_flags is obtained from the following table depending on the value of the parameter mode:`

`in  out  u_flags   +  O_RDONLY   +  O_WRONLY   +  +  O_RDWR   `

**Returns:**

`If the open() system call succeeds the method returns this. If the call fails, then it returns a null pointer. `

### SerialStreamBuf& LibSerial::SerialStreamBuf::operator= (const SerialStreamBuf &)` [private]`

### virtual int\_type LibSerial::SerialStreamBuf::overflow (int\_type c)` [protected]`, ` [virtual]`

`Writes the specified character to the associated serial port. `

**Returns:**

`The character c. `

### const ParityEnum LibSerial::SerialStreamBuf::Parity () const

`Get the current parity setting for the serial port. `

**Returns:**

`The parity setting for the serial port. `

### virtual int\_type LibSerial::SerialStreamBuf::pbackfail (int\_type c = `traits_type::eof()`)` [protected]`, ` [virtual]`

`This function is called when a putback of a character fails. This must be implemented for unbuffered I/O as all streambuf subclasses are required to provide putback of at least on character. `

### const BaudRateEnum LibSerial::SerialStreamBuf::SetBaudRate (const BaudRateEnum baudRate)

`If `**is\_open()**` != true, return -1. Otherwise, set the baud rate of the associated serial port. Return the baud rate on success and BAUD_INVALID on failure. `

### virtual std::streambuf\* LibSerial::SerialStreamBuf::setbuf (char\_type \*, std::streamsize)` [protected]`, ` [virtual]`

`Performs an operation that is defined separately for each class derived from streambuf. The default behavior is to do nothing if gptr() is non-null and gptr()!=egptr(). Also, setbuf(0, 0) usually means unbuffered I/O and setbuf(p, n) means use p[0]...p[n-1] to hold the buffered characters. In general, this method implements the subclass's notion of getting memory for the buffered characters.`

`In the case of `**SerialStreamBuf**`, we want to keep using unbuffered I/O. Hence, using this method has no effect at present. `

### const CharSizeEnum LibSerial::SerialStreamBuf::SetCharSize (const CharSizeEnum charSize)

`Set the character size to be used during serial communication. It returns the character size on success and CHAR_SIZE_INVALID on failure. `

### const FlowControlEnum LibSerial::SerialStreamBuf::SetFlowControl (const FlowControlEnum flowControlType)

`Use the specified flow control. `

### short LibSerial::SerialStreamBuf::SetNumOfStopBits (short numOfStopBits)

`Set the number of stop bits used during serial communication. The only valid values are 1 and 2.`

**Parameters:**

*stop\_bits*` The number of stop bits. (1 or 2). `

**Returns:**

`The number of stop bits or -1 on failure. `

### int LibSerial::SerialStreamBuf::SetParametersToDefault ()

`Initialize the serial communication parameters to their default values. `

### const ParityEnum LibSerial::SerialStreamBuf::SetParity (const ParityEnum parityType)

`Set the parity for serial communication. `

**Parameters:**

*parity*` The parity value. `

### const short LibSerial::SerialStreamBuf::SetVMin (short vtime)

`Set the minimum number of characters for non-canonical reads. See VMIN in man termios(3). `

### const short LibSerial::SerialStreamBuf::SetVTime (short vtime)

`Set character buffer timeout in 10ths of a second. This applies to non-canonical reads. `

### virtual std::streamsize LibSerial::SerialStreamBuf::showmanyc ()` [protected]`, ` [virtual]`

`Check, wether input is available on the port. If you call SerialStream::in_avail, this method will be called to check for available input. `

```
while( serial_port.rdbuf()->in_avail() > 0  ) {
  serial_port.get(ch);
  ...
}
```

### virtual int\_type LibSerial::SerialStreamBuf::uflow ()` [protected]`, ` [virtual]`

`Reads and returns the next character from the associated serial port if one otherwise returns traits::eof(). This method is used for unbuffered I/O while `**underflow()**` is called for unbuffered I/O.`

**Returns:**

`The next character from the serial port. `

### virtual int\_type LibSerial::SerialStreamBuf::underflow ()` [protected]`, ` [virtual]`

`Reads and returns the next character from the associated serial port if one otherwise returns traits::eof(). This method is used for buffered I/O while `**uflow()**` is called for unbuffered I/O.`

**Returns:**

`The next character from the serial port. `

### const short LibSerial::SerialStreamBuf::VMin () const

`Get the VMIN value for the device. This represents the minimum number of characters for non-canonical reads. `

### const short LibSerial::SerialStreamBuf::VTime () const

`Get the current timeout value for non-canonical reads in deciseconds. `

### virtual std::streamsize LibSerial::SerialStreamBuf::xsgetn (char\_type \* s, std::streamsize n)` [protected]`, ` [virtual]`

`Reads upto n characters from the serial port and returns them through the character array located at s. `

**Returns:**

`The number of characters actually read from the serial port. `

### virtual std::streamsize LibSerial::SerialStreamBuf::xsputn (const char\_type \* s, std::streamsize n)` [protected]`, ` [virtual]`

`Writes upto n characters from the character sequence at s to the serial port associated with the buffer. `

**Returns:**

`The number of characters that were successfully written to the serial port. `

## Member Data Documentation

### const char LibSerial::SerialStreamBuf::CTRL\_Q = 0x11` [static]`, ` [protected]`

`Character used to signal that I/O can start while using software flow control with the serial port. `

`Definition at line 428 of file SerialStreamBuf.h.`

### const char LibSerial::SerialStreamBuf::CTRL\_S = 0x13` [static]`, ` [protected]`

`Character used to signal that I/O should stop while using software flow control with the serial port. `

`Definition at line 434 of file SerialStreamBuf.h.`

### const BaudRateEnum LibSerial::SerialStreamBuf::DEFAULT\_BAUD` [static]`

`The default value of the baud rate of the serial port. `

**Deprecated**

`Please use `**SerialPort::BAUD\_DEFAULT**` instead. `

`Definition at line 160 of file SerialStreamBuf.h.`

### const CharSizeEnum LibSerial::SerialStreamBuf::DEFAULT\_CHAR\_SIZE` [static]`

`The default value of the character size used during the serial communication. `

**Deprecated**

`Please use `**SerialPort::CHAR\_SIZE\_DEFAULT**` instead. `

`Definition at line 169 of file SerialStreamBuf.h.`

### const FlowControlEnum LibSerial::SerialStreamBuf::DEFAULT\_FLOW\_CONTROL` [static]`

`The default flow control setting. `

**Deprecated**

`Please use `**SerialPort::FLOW\_CONTROL\_DEFAULT**` instead. `

`Definition at line 193 of file SerialStreamBuf.h.`

### const short LibSerial::SerialStreamBuf::DEFAULT\_NO\_OF\_STOP\_BITS` [static]`

`The default number of stop bits used. `

**Deprecated**

`Please use `**SerialPort::STOP\_BITS\_DEFAULT**` instead. `

`Definition at line 177 of file SerialStreamBuf.h.`

### const ParityEnum LibSerial::SerialStreamBuf::DEFAULT\_PARITY` [static]`

`The default parity setting. `

**Deprecated**

`Please use `**SerialPort::PARITY\_DEFAULT**` instead. `

`Definition at line 185 of file SerialStreamBuf.h.`

### const short LibSerial::SerialStreamBuf::DEFAULT\_VMIN` [static]`

`The default character buffer size. `

**Deprecated**

`VMIN and VTIME will not be supported starting from version 0.7.0. Methods of `**SerialPort**` class provide better mechanisms for implementing read and write timeouts. `

`Definition at line 203 of file SerialStreamBuf.h.`

### const short LibSerial::SerialStreamBuf::DEFAULT\_VTIME` [static]`

`The default character buffer timing. `

**Deprecated**

`VMIN and VTIME will not be supported starting from version 0.7.0. Methods of `**SerialPort**` class provide better mechanisms for implementing read and write timeouts. `

`Definition at line 213 of file SerialStreamBuf.h.`

### boost::scoped\_ptr\<Implementation\> LibSerial::SerialStreamBuf::mImpl` [private]`

`Definition at line 532 of file SerialStreamBuf.h.`

## Author

`Generated automatically by Doxygen for libserial from the source code.`
