|
GNU CommonC++
|
The serial port is an internal class which is attached to and then serviced by a specified SerialService thread. More...
#include <serial.h>
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... | |
| Serial & | operator= (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 |
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.
base class for thread pool serviced serial I/O.
|
protected |
Construct a tty serial port for a named serial device.
| svc | pool thread object. |
| name | of tty port. |
|
protectedvirtual |
Disconnect the Serial Port from the service pool thread and shutdown the port.
|
protectedvirtual |
Called by the service thread when an exception has occured such as a hangup.
|
protectedvirtual |
Called by the service thread when the objects timer has expired.
|
inlineprotected |
Get the current state of the DetectOutput flag.
|
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.
|
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.
| buf | address of buffer to input. |
| len | of input buffer used. |
|
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.
| buf | address of buffer to send. |
| len | of bytes to send. |
|
protectedvirtual |
Perform when output is available for sending data.
|
protectedvirtual |
Called by the service thread when input data is pending for this tty port.
Effected by setPacketInput and by setLineInput.
|
protected |
Used to indicate if output ready monitoring should be performed by the service thread.
|
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.
| timeout | in milliseconds. |
|
friend |