UCommon
Public Member Functions | Protected Member Functions | Friends
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:
Inheritance graph
[legend]
Collaboration diagram for ost::SerialPort:
Collaboration graph
[legend]

Public Member Functions

void incTimer (timeout_t timeout)
 Derived incTimer to notify the service thread pool of a change in expected timeout. More...
 
void setTimer (timeout_t timeout=0)
 Derived setTimer to notify the service thread pool of changes in expected timeout. More...
 
- Public Member Functions inherited from ost::Serial
int getBufferSize (void) const
 Get the "buffer" size for buffered operations. More...
 
Error getErrorNumber (void) const
 Often used by a "catch" to fetch the last error of a thrown serial. More...
 
char * getErrorString (void) const
 Often used by a "catch" to fetch the user set error string of a thrown serial. More...
 
virtual bool isPending (Pending pend, timeout_t timeout=ucommon::Timer::inf)
 Get the status of pending operations. More...
 
Serialoperator= (const Serial &from)
 Serial ports may also be duplecated by the assignment operator.
 
void sendBreak (void)
 Send the "break" signal.
 
Error setCharBits (int bits)
 Set character size. More...
 
Error setFlowControl (Flow flow)
 Set flow control. More...
 
Error setParity (Parity parity)
 Set parity mode. More...
 
Error setSpeed (unsigned long speed)
 Set serial port speed for both input and output. More...
 
Error setStopBits (int bits)
 Set number of stop bits. More...
 
void toggleDTR (timeout_t millisec)
 Set the DTR mode off momentarily. More...
 
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...
 
- Public Member Functions inherited from ost::TimerPort
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 endTimer (void)
 This is used to "disable" the service thread from expiring the timer object. 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...
 
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...
 
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 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 sleepTimer (void)
 Sleep until the current timer expires. More...
 
 TimerPort ()
 Create a timer, mark it as inactive, and set the initial "start" time to the creation time of the timer object. More...
 

Protected Member Functions

virtual void disconnect (void)
 Called by the service thread when an exception has occured such as a hangup.
 
virtual void expired (void)
 Called by the service thread when the objects timer has expired.
 
bool getDetectOutput (void) const
 Get the current state of the DetectOutput flag.
 
bool getDetectPending (void) const
 Get the current state of the DetectPending flag.
 
int input (void *buf, int len)
 Receive "input" for pending data from the serial port. 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.
 
virtual void pending (void)
 Called by the service thread when input data is pending for this tty port. More...
 
 SerialPort (SerialService *svc, const char *name)
 Construct a tty serial port for a named serial device. More...
 
void setDetectOutput (bool)
 Used to indicate if output ready monitoring should be performed by the service thread.
 
void setDetectPending (bool)
 Used to indicate if the service thread should monitor pending data for us.
 
virtual ~SerialPort ()
 Disconnect the Serial Port from the service pool thread and shutdown the port.
 
- Protected Member Functions inherited from ost::Serial
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...
 
void close (void)
 Closes the serial device.
 
void endSerial (void)
 Used as the default destructor for ending serial I/O services. 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 flushInput (void)
 Used to flush the input waiting queue.
 
void flushOutput (void)
 Used to flush any pending output data.
 
void initConfig (void)
 Used to initialize a newly opened serial file handle. More...
 
void open (const char *fname)
 Opens the serial device. More...
 
void restore (void)
 Restore serial device to the original settings at time of open.
 
 Serial ()
 This allows later ttystream class to open and close a serial device.
 
 Serial (const char *name)
 A serial object may be constructed from a named file on the file system. 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 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...
 
int setPacketInput (int size, uint8_t btimer=0)
 Set packet read mode and "size" of packet read buffer. More...
 
void waitOutput (void)
 Used to wait until all output has been sent.
 

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
}
 
typedef enum Error Error
 
enum  Flow { flowNone, flowSoft, flowHard, flowBoth }
 
typedef enum Flow Flow
 
enum  Parity { parityNone, parityOdd, parityEven }
 
typedef enum Parity Parity
 
enum  Pending { pendingInput, pendingOutput, pendingError }
 
typedef enum Pending Pending
 
- Protected Attributes inherited from ost::Serial
int bufsize
 
fd_t dev
 

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.

Definition at line 638 of file serial.h.

Constructor & Destructor Documentation

◆ SerialPort()

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.

Member Function Documentation

◆ incTimer()

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.

◆ input()

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.

Definition at line 741 of file serial.h.

◆ output()

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.

Definition at line 723 of file serial.h.

◆ pending()

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.

◆ setTimer()

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.

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