Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

lfc::SerialPort Class Reference

encapsulate a serial communication port. More...

Inheritance diagram for lfc::SerialPort::

lfc::Object lfc::_Input< char > lfc::_Output< char > lfc::_Named lfc::_Server lfc::_Server List of all members.

Public Types

enum  State { stOpen, stClosed }
 the states in which a SerialPort can be. More...

enum  PurgeFlags { purgeInput = pal::serial::purgeInput, purgeOutput = pal::serial::purgeOutput }
 purge buffer flags. More...

enum  ModemStatusFlags { mstatusDSR = pal::serial::mstatusDSR, mstatusCTS = pal::serial::mstatusCTS, mstatusDCD = pal::serial::mstatusDCD, mstatusRNG = pal::serial::mstatusRNG }
 modem status flags. More...


Public Methods

 SerialPort () throw ()
 construct an closed serial port object. More...

 SerialPort (string name)
 construct an opened serial port object. More...

virtual ~SerialPort () throw ()
virtual char pop ()
virtual void resetInput ()
virtual bool hasMore () const
virtual long read (char *buffer, long count, bool bWaitAll=true)
virtual void push (const char &value)
virtual void resetOutput ()
virtual bool acceptMore () const
virtual void flush ()
virtual long write (const char *buffer, long count, bool bWaitAll=true)
virtual void open (string name)
 open serial port. More...

virtual void close ()
 close the port. More...

virtual long availableCount () const
 return the number of bytes available in the input buffer. More...

virtual void setup (string settings)
 set serial port settings (baud rate, parity, ...). More...

virtual void setHardwareFlowControl (bool bEnable)
 enable/disable hardware flow control (CTS/RTS). More...

virtual void setSoftwareFlowControl (bool bEnable, char Xon=0x11, char Xoff=0x13)
 enable/disable software flow control (XON/XOFF). More...

virtual void setReadTimeout (long timeout)
 set input timeouts. More...

virtual void setBlockingRead (bool bBlocking)
 enable/disable blocking read. More...

virtual void sendBreak ()
 send a 500ms break. More...

virtual DWord modemStatus () const
 return modem status bits. More...

virtual void setDTR (bool bEnable)
 enable/disable DTR. More...

virtual void setRTS (bool bEnable)
 enable/disable RTS. More...

virtual State state () const throw ()
 return current SerialPort state. More...


Protected Methods

virtual void testState (string location, int s1, int s2=-1, int s3=-1, int s4=-1) const

Protected Attributes

pal::serial::Handle m_handle
pal::serial::PortSettings m_originalSettings
State m_state

Detailed Description

encapsulate a serial communication port.

Todo:
present some usage samples here...

make this thread safe


Member Enumeration Documentation

enum lfc::SerialPort::State
 

the states in which a SerialPort can be.

Enumeration values:
stOpen 
stClosed 

enum lfc::SerialPort::PurgeFlags
 

purge buffer flags.

Enumeration values:
purgeInput 
purgeOutput 

enum lfc::SerialPort::ModemStatusFlags
 

modem status flags.

Enumeration values:
mstatusDSR 
mstatusCTS 
mstatusDCD 
mstatusRNG 


Constructor & Destructor Documentation

lfc::SerialPort::SerialPort   throw ()
 

construct an closed serial port object.

lfc::SerialPort::SerialPort string    name
 

construct an opened serial port object.

lfc::SerialPort::~SerialPort   throw () [virtual]
 

close serial port if open


Member Function Documentation

char lfc::SerialPort::pop   [virtual]
 

Returns:
the char that was read from serial port
See also:
read

Reimplemented from lfc::_Input.

void lfc::SerialPort::resetInput   [virtual]
 

purge input buffer content

Reimplemented from lfc::_Input.

bool lfc::SerialPort::hasMore   const [virtual]
 

Returns:
allways true

Reimplemented from lfc::_Input.

long lfc::SerialPort::read char *    buffer,
long    count,
bool    bWaitAll = true
[virtual]
 

Parameters:
buffer  will receive read bytes
count  the requested number of bytes (might return less bytes if bWaitAll is false)
em bWaitAll if true will try to read exactly count bytes (or throw an exception if fail)
Returns:
the number of bytes actually read

void lfc::SerialPort::push const char &    value [virtual]
 

Parameters:
value  the byte to be written
See also:
write

void lfc::SerialPort::resetOutput   [virtual]
 

purge output buffer contents

Reimplemented from lfc::_Output.

bool lfc::SerialPort::acceptMore   const [virtual]
 

Returns:
allways true

Reimplemented from lfc::_Output.

void lfc::SerialPort::flush   [virtual]
 

Reimplemented from lfc::_Output.

long lfc::SerialPort::write const char *    buffer,
long    count,
bool    bWaitAll = true
[virtual]
 

Parameters:
buffer  with bytes to be written
count  the requested number of bytes (might write fewer bytes if bWaitAll is false)
em bWaitAll if true will try to write exactly count bytes (or throw an exception if fail)
Returns:
the number of bytes actually written

void lfc::SerialPort::open string    name [virtual]
 

open serial port.

Parameters:
name  serial port name (ex. "com1" under win32, "/dev/ttyS0" under Linux)
Note:
will save original port settings

void lfc::SerialPort::close   [virtual]
 

close the port.

close serial port (if it's open, else do nothing)

Note:
will restore original port settings

long lfc::SerialPort::availableCount   const [virtual]
 

return the number of bytes available in the input buffer.

void lfc::SerialPort::setup string    settings [virtual]
 

set serial port settings (baud rate, parity, ...).

Parameters:
settings  describe port settings in the following format: <baud>,

<S> where

  • baud is serial transmition speed
  • B is byte size (4..8)
  • P is parity (n-none, o-odd, e-even, s-space)
  • S is stop bits (1 or 2)
    Note:
    settings string is not case sensitive and it can't containt whitespaces

void lfc::SerialPort::setHardwareFlowControl bool    bEnable [virtual]
 

enable/disable hardware flow control (CTS/RTS).

Parameters:
bEnable  if true enable hardware flow control, else disable

void lfc::SerialPort::setSoftwareFlowControl bool    bEnable,
char    Xon = 0x11,
char    Xoff = 0x13
[virtual]
 

enable/disable software flow control (XON/XOFF).

Parameters:
bEnable  if true enable software flow control, else disable
Xon  XON character
Xoff  XOFF character

void lfc::SerialPort::setReadTimeout long    timeout [virtual]
 

set input timeouts.

Parameters:
timeout  time (in ms) to wait until a char is received

void lfc::SerialPort::setBlockingRead bool    bBlocking [virtual]
 

enable/disable blocking read.

void lfc::SerialPort::sendBreak   [virtual]
 

send a 500ms break.

DWord lfc::SerialPort::modemStatus   const [virtual]
 

return modem status bits.

Returns:
modem status bits, as a bitwise combination of the following:
  • mstatusCTS - clear to send
  • mstatusDSR - data set ready
  • mstatusRNG - ring
  • mstatusDCD - data carrier detect

void lfc::SerialPort::setDTR bool    bEnable [virtual]
 

enable/disable DTR.

void lfc::SerialPort::setRTS bool    bEnable [virtual]
 

enable/disable RTS.

virtual State lfc::SerialPort::state   const throw () [inline, virtual]
 

return current SerialPort state.

virtual void lfc::SerialPort::testState string    location,
int    s1,
int    s2 = -1,
int    s3 = -1,
int    s4 = -1
const [inline, protected, virtual]
 


Member Data Documentation

pal::serial::Handle lfc::SerialPort::m_handle [protected]
 

pal::serial::PortSettings lfc::SerialPort::m_originalSettings [protected]
 

State lfc::SerialPort::m_state [protected]
 


The documentation for this class was generated from the following files:
Generated on Fri Jan 25 03:13:49 2002 for LFC2 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001