Bayonne2 / Common C++ 2 Framework
|
The Serial class is used as the base for all serial I/O services under APE. More...
#include <serial.h>
Public Types | |
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 |
Public Member Functions | |
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... | |
Protected Member Functions | |
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... | |
Protected Attributes | |
HANDLE | dev |
int | bufsize |
Private Member Functions | |
void | initSerial (void) |
Used to properly initialize serial object. More... | |
Private Attributes | |
Error | errid |
char * | errstr |
struct { | |
bool thrown: 1 | |
bool linebuf: 1 | |
} | flags |
void * | original |
void * | current |
The Serial class is used as the base for all serial I/O services under APE.
A serial is a system serial port that is used either for line or packet based data input. Serial ports may also be "streamable" in a derived form.
Common C++ serial I/O classes are used to manage serial devices and implement serial device protocols. From the point of view of Common C++, serial devices are supported by the underlying Posix specified "termios" call interface.
The serial I/O base class is used to hold a descriptor to a serial device and to provide an exception handling interface for all serial I/O classes. The base class is also used to specify serial I/O properties such as communication speed, flow control, data size, and parity. The "Serial" base class is not itself directly used in application development, however.
Common C++ Serial I/O is itself divided into two conceptual modes; frame oriented and line oriented I/O. Both frame and line oriented I/O makes use of the ability of the underlying tty driver to buffer data and return "ready" status from when select either a specified number of bytes or newline record has been reached by manipulating termios c_cc fields appropriately. This provides some advantage in that a given thread servicing a serial port can block and wait rather than have to continually poll or read each and every byte as soon as it appears at the serial port.
typedef enum Error Serial::Error |
typedef enum Flow Serial::Flow |
typedef enum Parity Serial::Parity |
typedef enum Pending Serial::Pending |
enum Serial::Error |
enum Serial::Flow |
enum Serial::Parity |
enum Serial::Pending |
|
inlineprotected |
|
protected |
A serial object may be constructed from a named file on the file system.
This named device must be "isatty()".
name | of file. |
|
virtual |
The serial base class may be "thrown" as a result on an error, and the "catcher" may then choose to destory the object.
By assuring the socket base class is a virtual destructor, we can assure the full object is properly terminated.
|
protectedvirtual |
Reads from serial device.
Data | Point to character buffer to receive data. Buffers MUST be at least Length + 1 bytes in size. |
Length | Number of bytes to read. |
|
protectedvirtual |
Writes to serial device.
Data | Point to character buffer containing data to write. Buffers MUST |
Length | Number of bytes to write. |
|
protected |
Closes the serial device.
|
protected |
Used as the default destructor for ending serial I/O services.
It will restore the port to it's original state.
This service is used to throw all serial errors which usually occur during the serial constructor.
error | defined serial error id. |
errstr | string or message to optionally pass. |
|
inlineprotected |
|
protected |
Used to flush the input waiting queue.
|
protected |
Used to flush any pending output data.
|
inline |
|
inline |
|
inline |
|
protected |
Used to initialize a newly opened serial file handle.
You should set serial properties and DTR manually before first use.
|
private |
Used to properly initialize serial object.
|
virtual |
Get the status of pending operations.
This can be used to examine if input or output is waiting, or if an error has occured on the serial device.
pend | ready check to perform. |
timeout | in milliseconds. |
Reimplemented in TTYStream.
|
protected |
Opens the serial device.
fname | Pathname of device to open |
Serial ports may also be duplecated by the assignment operator.
|
protected |
Restore serial device to the original settings at time of open.
void Serial::sendBreak | ( | void | ) |
Send the "break" signal.
Error Serial::setCharBits | ( | int | bits | ) |
Set character size.
bits | character size to use (usually 7 or 8). |
|
inlineprotected |
Set flow control.
flow | control mode. |
|
protected |
Set "line buffering" read mode and specifies the newline character to be used in seperating line records.
isPending can then be used to wait for an entire line of input.
newline | newline character. |
nl1 | EOL2 control character. |
|
protected |
Set packet read mode and "size" of packet read buffer.
This sets VMIN to x. VTIM is normally set to "0" so that "isPending()" can wait for an entire packet rather than just the first byte.
size | of packet read request. |
btimer | optional inter-byte data packet timeout. |
Set parity mode.
parity | mode. |
Error Serial::setSpeed | ( | unsigned long | speed | ) |
Set serial port speed for both input and output.
speed | to select. 0 signifies modem "hang up". |
Error Serial::setStopBits | ( | int | bits | ) |
Set number of stop bits.
bits | stop bits. |
void Serial::toggleDTR | ( | timeout_t | millisec | ) |
Set the DTR mode off momentarily.
millisec | number of milliseconds. |
|
protected |
Used to wait until all output has been sent.
struct { ... } Serial::flags |