SerialStream.h
Go to the documentation of this file.
/*
* Time-stamp: <2008-10-30 16:30:11 pagey>
*
* $Id: SerialStream.h,v 1.10 2005-10-01 21:24:21 crayzeewulf Exp $
*
*
*/
#ifndef _SerialStream_h_
#define _SerialStream_h_
#include <string>
#include <fstream>
#include <SerialStreamBuf.h>
extern "C++" {
namespace LibSerial {
class SerialStream : public std::iostream {
public:
/* ------------------------------------------------------------
* Public Static Members
* ------------------------------------------------------------ */
explicit SerialStream( const std::string fileName,
std::ios_base::openmode openMode =
std::ios::in|std::ios::out) ;
SerialStream( const std::string fileName,
const SerialStreamBuf::BaudRateEnum baudRate = SerialStreamBuf::DEFAULT_BAUD,
const SerialStreamBuf::CharSizeEnum charSize = SerialStreamBuf::DEFAULT_CHAR_SIZE,
const SerialStreamBuf::ParityEnum parityType = SerialStreamBuf::DEFAULT_PARITY,
const short numOfStopBits = SerialStreamBuf::DEFAULT_NO_OF_STOP_BITS,
const SerialStreamBuf::FlowControlEnum flowControlType = SerialStreamBuf::DEFAULT_FLOW_CONTROL ) ;
explicit SerialStream() ;
virtual ~SerialStream() ;
void Open( const std::string fileName,
std::ios_base::openmode openMode =
std::ios_base::in | std::ios_base::out) ;
void Close() ;
const bool IsOpen() const ;
void SetBaudRate(SerialStreamBuf::BaudRateEnum baudRate ) ;
const SerialStreamBuf::BaudRateEnum BaudRate() ;
void SetCharSize(const SerialStreamBuf::CharSizeEnum charSize ) ;
const SerialStreamBuf::CharSizeEnum CharSize() ;
void SetNumOfStopBits(short numOfStopBits) ;
const short NumOfStopBits() ;
void SetParity(const SerialStreamBuf::ParityEnum parityType) ;
const SerialStreamBuf::ParityEnum Parity() ;
void
SetFlowControl(const SerialStreamBuf::FlowControlEnum flowControlType) ;
const SerialStreamBuf::FlowControlEnum FlowControl() ;
const short SetVMin( short vtime ) ;
const short VMin() ;
const short SetVTime( short vtime ) ;
const short VTime() ;
/* ------------------------------------------------------------
* Friends
* ------------------------------------------------------------
*/
protected:
/* ------------------------------------------------------------
* Protected Data Members
* ------------------------------------------------------------
*/
/* ------------------------------------------------------------
* Protected Methods
* ------------------------------------------------------------
*/
private:
/* ------------------------------------------------------------
* Private Data Members
* ------------------------------------------------------------
*/
//
// The copy constructor and the assignment operator are declared
// but never defined. This allows the compiler to catch any
// attempts to copy instances of this class.
//
SerialStream( const SerialStream& ) ;
SerialStream& operator=( const SerialStream& ) ;
SerialStreamBuf *mIOBuffer ;
/* ----------------------------------------------------------------
* Private Methods
* ----------------------------------------------------------------
*/
/* Set the serial port to ignore the modem status lines. If the
specified boolean parameter is false then the meaning of
this function is reversed i.e. the serial port will start
using the modem status lines.
@param ignore If true then the modem status lines will be
ignored otherwise they will be used during the
communication.
*/
//void IgnoreModemStatusLines(bool ignore=true) ;
/* Enable the serial port receiver. This will allow us to read
data from the serial port.
@param enable If true then the received will be
enabled. Otherwise it will be disabled.
*/
//void EnableReceiver(bool enable=true) ;
} ; // class SerialStream
inline
SerialStream::SerialStream() :
std::iostream(0), mIOBuffer(0) {
//
// Close the stream
//
Close() ;
}
inline
SerialStream::~SerialStream() {
//
// If a SerialStreamBuf is associated with this SerialStream
// then we need to destroy it here.
//
if( mIOBuffer ) {
delete mIOBuffer ;
}
}
inline
void
SerialStream::Close() {
//
// If a SerialStreamBuf is associated with the SerialStream then
// destroy it.
//
if( mIOBuffer ) {
delete mIOBuffer ;
mIOBuffer = 0 ;
}
}
inline
const bool
SerialStream::IsOpen() const {
//
// Checks to see if mIOBuffer is a null buffer, if not,
// calls the is_open() function on this streams SerialStreamBuf,
// mIOBuffer
//
if ( ! mIOBuffer ) {
return false ;
}
return mIOBuffer->is_open() ;
}
} // namespace LibSerial
} // extern "C++"
#endif // #ifndef _SerialStream_h_
LibSerial::SerialStreamBuf::FlowControlEnum
FlowControlEnum
The values of the flow control settings for a serial port.
Definition: SerialStreamBuf.h:130
LibSerial::SerialStreamBuf::DEFAULT_PARITY
static const ParityEnum DEFAULT_PARITY
The default parity setting.
Definition: SerialStreamBuf.h:178
LibSerial::SerialStreamBuf::CharSizeEnum
CharSizeEnum
The allowed values of character sizes that can be used during the serial communication.
Definition: SerialStreamBuf.h:97
LibSerial::SerialStream::SetBaudRate
void SetBaudRate(SerialStreamBuf::BaudRateEnum baudRate)
Set the baud rate for serial communications.
LibSerial::SerialStream::NumOfStopBits
const short NumOfStopBits()
Get the number of stop bits being used during serial communication.
LibSerial::SerialStream::Open
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.
LibSerial::SerialStream::BaudRate
const SerialStreamBuf::BaudRateEnum BaudRate()
Get the current baud rate being used for serial communication.
LibSerial::SerialStream::VTime
const short VTime()
Get current timing of character buffer in 10th of a second.
LibSerial::SerialStream::FlowControl
const SerialStreamBuf::FlowControlEnum FlowControl()
Return the current flow control setting.
LibSerial::SerialStreamBuf::DEFAULT_CHAR_SIZE
static const CharSizeEnum DEFAULT_CHAR_SIZE
The default value of the character size used during the serial communication.
Definition: SerialStreamBuf.h:162
LibSerial::SerialStreamBuf::DEFAULT_FLOW_CONTROL
static const FlowControlEnum DEFAULT_FLOW_CONTROL
The default flow control setting.
Definition: SerialStreamBuf.h:186
LibSerial::SerialStream::operator=
SerialStream & operator=(const SerialStream &)
LibSerial::SerialStream::SetNumOfStopBits
void SetNumOfStopBits(short numOfStopBits)
Set the number of stop bits used during serial communication.
LibSerial::SerialStream::SetParity
void SetParity(const SerialStreamBuf::ParityEnum parityType)
Set the parity for serial communication.
LibSerial::SerialStream::SetVMin
const short SetVMin(short vtime)
Set character buffer size.
LibSerial::SerialStream::CharSize
const SerialStreamBuf::CharSizeEnum CharSize()
Get the character size being used for serial communication.
LibSerial::SerialStream::mIOBuffer
SerialStreamBuf * mIOBuffer
The SerialStreamBuf object that will be used by the stream to communicate with the serial port...
Definition: SerialStream.h:274
SerialStreamBuf.h
LibSerial::SerialStreamBuf::BaudRateEnum
BaudRateEnum
The baud rates currently supported by the SUS-2 general terminal interface specification.
Definition: SerialStreamBuf.h:62
LibSerial::SerialStream::SetVTime
const short SetVTime(short vtime)
Set character buffer timing in 10th of a second.
LibSerial::SerialStream::SerialStream
SerialStream()
Create a new SerialStream object but do not open it.
Definition: SerialStream.h:304
LibSerial::SerialStreamBuf::is_open
bool is_open() const
Returns true if a previous call to open() succeeded (returned a non-null value) and there has been no...
Definition: SerialStreamBuf.h:583
LibSerial::SerialStreamBuf::ParityEnum
ParityEnum
The allowed values of the parity associated with the serial port communications.
Definition: SerialStreamBuf.h:114
LibSerial::SerialStream::Parity
const SerialStreamBuf::ParityEnum Parity()
Get the current parity setting for the serial port.
LibSerial::SerialStream
A stream class for accessing serial ports on POSIX operating systems.
Definition: SerialStream.h:50
LibSerial::SerialStreamBuf
This is the streambuf subclass used by SerialStream.
Definition: SerialStreamBuf.h:38
LibSerial::SerialStream::IsOpen
const bool IsOpen() const
Returns true if the Stream is in a good open state, false otherwise.
Definition: SerialStream.h:338
LibSerial::SerialStream::VMin
const short VMin()
Get current size of character buffer.
LibSerial::SerialStream::Close
void Close()
Close the serial port.
Definition: SerialStream.h:325
LibSerial::SerialStream::SetCharSize
void SetCharSize(const SerialStreamBuf::CharSizeEnum charSize)
Set the character size associated with the serial port.
LibSerial::SerialStreamBuf::DEFAULT_NO_OF_STOP_BITS
static const short DEFAULT_NO_OF_STOP_BITS
The default number of stop bits used.
Definition: SerialStreamBuf.h:170
LibSerial::SerialStream::~SerialStream
virtual ~SerialStream()
The destructor.
Definition: SerialStream.h:313
LibSerial::SerialStreamBuf::DEFAULT_BAUD
static const BaudRateEnum DEFAULT_BAUD
The default value of the baud rate of the serial port.
Definition: SerialStreamBuf.h:153
LibSerial::SerialStream::SetFlowControl
void SetFlowControl(const SerialStreamBuf::FlowControlEnum flowControlType)
Use the specified flow control.