GNU CommonC++
Public Member Functions | Protected Member Functions | Friends | List of all members
ost::SerialPort Class Reference

The serial port is an internal class which is attached to and then serviced by a specified SerialService thread. More...

#include <serial.h>

Inheritance diagram for ost::SerialPort:
ost::Serial ost::TimerPort

Public Member Functions

void setTimer (timeout_t timeout=0)
 Derived setTimer to notify the service thread pool of changes in expected timeout. More...
 
void incTimer (timeout_t timeout)
 Derived incTimer to notify the service thread pool of a change in expected timeout. More...
 
- Public Member Functions inherited from ost::Serial
virtual ~Serial ()
 The serial base class may be "thrown" as a result on an error, and the "catcher" may then choose to destory the object. More...
 
Serialoperator= (const Serial &from)
 Serial ports may also be duplecated by the assignment operator. More...
 
Error setSpeed (unsigned long speed)
 Set serial port speed for both input and output. More...
 
Error setCharBits (int bits)
 Set character size. More...
 
Error setParity (Parity parity)
 Set parity mode. More...
 
Error setStopBits (int bits)
 Set number of stop bits. More...
 
Error setFlowControl (Flow flow)
 Set flow control. More...
 
void toggleDTR (timeout_t millisec)
 Set the DTR mode off momentarily. More...
 
void sendBreak (void)
 Send the "break" signal. More...
 
Error getErrorNumber (void)
 Often used by a "catch" to fetch the last error of a thrown serial. More...
 
char * getErrorString (void)
 Often used by a "catch" to fetch the user set error string of a thrown serial. More...
 
int getBufferSize (void)
 Get the "buffer" size for buffered operations. More...
 
virtual bool isPending (Pending pend, timeout_t timeout=TIMEOUT_INF)
 Get the status of pending operations. More...
 
- Public Member Functions inherited from ost::TimerPort
 TimerPort ()
 Create a timer, mark it as inactive, and set the initial "start" time to the creation time of the timer object. More...
 
void setTimer (timeout_t timeout=0)
 Set a new start time for the object based on when this call is made and optionally activate the timer for a specified number of milliseconds. More...
 
void incTimer (timeout_t timeout)
 Set a timeout based on the current time reference value either from object creation or the last setTimer(). More...
 
void decTimer (timeout_t timeout)
 Adjust a timeout based on the current time reference value either from object creation or the last setTimer(). More...
 
void sleepTimer (void)
 Sleep until the current timer expires. More...
 
void endTimer (void)
 This is used to "disable" the service thread from expiring the timer object. More...
 
timeout_t getTimer (void) const
 This is used by service threads to determine how much time remains before the timer expires based on a timeout specified in setTimer() or incTimer(). More...
 
timeout_t getElapsed (void) const
 This is used to determine how much time has elapsed since a timer port setTimer benchmark time was initially set. More...
 

Protected Member Functions

 SerialPort (SerialService *svc, const char *name)
 Construct a tty serial port for a named serial device. More...
 
virtual ~SerialPort ()
 Disconnect the Serial Port from the service pool thread and shutdown the port. More...
 
void setDetectPending (bool)
 Used to indicate if the service thread should monitor pending data for us. More...
 
bool getDetectPending (void) const
 Get the current state of the DetectPending flag. More...
 
void setDetectOutput (bool)
 Used to indicate if output ready monitoring should be performed by the service thread. More...
 
bool getDetectOutput (void) const
 Get the current state of the DetectOutput flag. More...
 
virtual void expired (void)
 Called by the service thread when the objects timer has expired. More...
 
virtual void pending (void)
 Called by the service thread when input data is pending for this tty port. More...
 
virtual void disconnect (void)
 Called by the service thread when an exception has occured such as a hangup. More...
 
int output (void *buf, int len)
 Transmit "send" data to the serial port. More...
 
virtual void output (void)
 Perform when output is available for sending data. More...
 
int input (void *buf, int len)
 Receive "input" for pending data from the serial port. More...
 
- Protected Member Functions inherited from ost::Serial
void open (const char *fname)
 Opens the serial device. More...
 
void close (void)
 Closes the serial device. More...
 
virtual int aRead (char *Data, const int Length)
 Reads from serial device. More...
 
virtual int aWrite (const char *Data, const int Length)
 Writes to serial device. More...
 
Error error (Error error, char *errstr=NULL)
 This service is used to throw all serial errors which usually occur during the serial constructor. More...
 
void error (char *err)
 This service is used to thow application defined serial errors where the application specific error code is a string. More...
 
void setError (bool enable)
 This method is used to turn the error handler on or off for "throwing" execptions by manipulating the thrown flag. More...
 
int setPacketInput (int size, unsigned char btimer=0)
 Set packet read mode and "size" of packet read buffer. More...
 
int setLineInput (char newline=13, char nl1=0)
 Set "line buffering" read mode and specifies the newline character to be used in seperating line records. More...
 
void restore (void)
 Restore serial device to the original settings at time of open. More...
 
void flushInput (void)
 Used to flush the input waiting queue. More...
 
void flushOutput (void)
 Used to flush any pending output data. More...
 
void waitOutput (void)
 Used to wait until all output has been sent. More...
 
void endSerial (void)
 Used as the default destructor for ending serial I/O services. More...
 
void initConfig (void)
 Used to initialize a newly opened serial file handle. More...
 
 Serial ()
 This allows later ttystream class to open and close a serial device. More...
 
 Serial (const char *name)
 A serial object may be constructed from a named file on the file system. More...
 

Friends

class SerialService
 

Additional Inherited Members

- Public Types inherited from ost::Serial
enum  Error {
  errSuccess = 0, errOpenNoTty, errOpenFailed, errSpeedInvalid,
  errFlowInvalid, errParityInvalid, errCharsizeInvalid, errStopbitsInvalid,
  errOptionInvalid, errResourceFailure, errOutput, errInput,
  errTimeout, errExtended
}
 
enum  Flow { flowNone, flowSoft, flowHard, flowBoth }
 
enum  Parity { parityNone, parityOdd, parityEven }
 
enum  Pending { pendingInput, pendingOutput, pendingError }
 
typedef enum Error Error
 
typedef enum Flow Flow
 
typedef enum Parity Parity
 
typedef enum Pending Pending
 
- Protected Attributes inherited from ost::Serial
HANDLE dev
 
int bufsize
 

Detailed Description

The serial port is an internal class which is attached to and then serviced by a specified SerialService thread.

Derived versions of this class offer specific functionality such as serial integration protocols.

The TTYPort and TTYService classes are used to form thread-pool serviced serial I/O protocol sets. These can be used when one has a large number of serial devices to manage, and a single (or limited number of) thread(s) can then be used to service the tty port objects present. Each tty port supports a timer control and several virtual methods that the service thread can call when events occur. This model provides for "callback" event management, whereby the service thread performs a "callback" into the port object when events occur. Specific events supported include the expiration of a TTYPort timer, pending input data waiting to be read, and "sighup" connection breaks.

Author
David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m base class for thread pool serviced serial I/O.

Constructor & Destructor Documentation

ost::SerialPort::SerialPort ( SerialService svc,
const char *  name 
)
protected

Construct a tty serial port for a named serial device.

Parameters
svcpool thread object.
nameof tty port.
virtual ost::SerialPort::~SerialPort ( )
protectedvirtual

Disconnect the Serial Port from the service pool thread and shutdown the port.

Member Function Documentation

virtual void ost::SerialPort::disconnect ( void  )
protectedvirtual

Called by the service thread when an exception has occured such as a hangup.

virtual void ost::SerialPort::expired ( void  )
protectedvirtual

Called by the service thread when the objects timer has expired.

bool ost::SerialPort::getDetectOutput ( void  ) const
inlineprotected

Get the current state of the DetectOutput flag.

bool ost::SerialPort::getDetectPending ( void  ) const
inlineprotected

Get the current state of the DetectPending flag.

void ost::SerialPort::incTimer ( timeout_t  timeout)

Derived incTimer to notify the service thread pool of a change in expected timeout.

This allows SerialService to reschedule all timers.

int ost::SerialPort::input ( void *  buf,
int  len 
)
inlineprotected

Receive "input" for pending data from the serial port.

This is not a public member since it's meant to support internal protocols rather than direct external access to the device.

Returns
number of bytes received.
Parameters
bufaddress of buffer to input.
lenof input buffer used.
int ost::SerialPort::output ( void *  buf,
int  len 
)
inlineprotected

Transmit "send" data to the serial port.

This is not public since it's meant to support internal protocols rather than direct public access to the device.

Returns
number of bytes send.
Parameters
bufaddress of buffer to send.
lenof bytes to send.
virtual void ost::SerialPort::output ( void  )
protectedvirtual

Perform when output is available for sending data.

virtual void ost::SerialPort::pending ( void  )
protectedvirtual

Called by the service thread when input data is pending for this tty port.

Effected by setPacketInput and by setLineInput.

void ost::SerialPort::setDetectOutput ( bool  )
protected

Used to indicate if output ready monitoring should be performed by the service thread.

void ost::SerialPort::setDetectPending ( bool  )
protected

Used to indicate if the service thread should monitor pending data for us.

void ost::SerialPort::setTimer ( timeout_t  timeout = 0)

Derived setTimer to notify the service thread pool of changes in expected timeout.

This allows SerialService to reschedule all timers.

Parameters
timeoutin milliseconds.

Friends And Related Function Documentation

friend class SerialService
friend

The documentation for this class was generated from the following file: