Bayonne2 / Common C++ 2 Framework
|
TTY streams are used to represent serial connections that are fully "streamable" objects using C++ stream classes and friends. More...
#include <serial.h>
Public Types | |
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 |
Public Member Functions | |
TTYStream (const char *filename, timeout_t to=0) | |
Create and open a tty serial port. More... | |
virtual | ~TTYStream () |
End the tty stream and cleanup. More... | |
void | setTimeout (timeout_t to) |
Set the timeout control. More... | |
void | interactive (bool flag) |
Set tty mode to buffered or "interactive". More... | |
int | sync (void) |
Flushes the stream input and out buffers, writes pending output. More... | |
bool | isPending (Pending pend, timeout_t timeout=TIMEOUT_INF) |
Get the status of pending operations. 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... | |
Protected Member Functions | |
TTYStream () | |
This constructor is used to derive "ttystream", a more C++ style version of the TTYStream class. More... | |
void | allocate (void) |
Used to allocate the buffer space needed for iostream operations. More... | |
void | endStream (void) |
Used to terminate the buffer space and clean up the tty connection. More... | |
int | underflow (void) |
This streambuf method is used to load the input buffer through the established tty serial port. More... | |
int | uflow (void) |
This streambuf method is used for doing unbuffered reads through the establish tty serial port when in interactive mode. More... | |
int | overflow (int ch) |
This streambuf method is used to write the output buffer through the established tty port. More... | |
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... | |
Protected Attributes | |
char * | gbuf |
char * | pbuf |
timeout_t | timeout |
HANDLE | dev |
int | bufsize |
Private Member Functions | |
int | doallocate () |
Friends | |
TTYStream & | crlf (TTYStream &) |
TTYStream & | lfcr (TTYStream &) |
TTY streams are used to represent serial connections that are fully "streamable" objects using C++ stream classes and friends.
The first application relevant serial I/O class is the TTYStream class. TTYStream offers a linearly buffered "streaming" I/O session with the serial device. Furthermore, traditional C++ "stream" operators (<< and >>) may be used with the serial device. A more "true" to ANSI C++ library format "ttystream" is also available, and this supports an "open" method in which one can pass initial serial device parameters immediately following the device name in a single string, as in "/dev/tty3a:9600,7,e,1", as an example.
The TTYSession aggragates a TTYStream and a Common C++ Thread which is assumed to be the execution context that will be used to perform actual I/O operations. This class is very anagolous to TCPSession.
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
protected |
This constructor is used to derive "ttystream", a more C++ style version of the TTYStream class.
TTYStream::TTYStream | ( | const char * | filename, |
timeout_t | to = 0 |
||
) |
Create and open a tty serial port.
filename | char name of device to open. |
to | default timeout. |
|
virtual |
End the tty stream and cleanup.
|
protected |
Used to allocate the buffer space needed for iostream operations.
This is based on MAX_INPUT.
|
protectedvirtualinherited |
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. |
|
protectedvirtualinherited |
Writes to serial device.
Data | Point to character buffer containing data to write. Buffers MUST |
Length | Number of bytes to write. |
|
protectedinherited |
Closes the serial device.
|
private |
|
protectedinherited |
Used as the default destructor for ending serial I/O services.
It will restore the port to it's original state.
|
protected |
Used to terminate the buffer space and clean up the tty connection.
This function is called by the destructor.
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. |
|
inlineprotectedinherited |
|
protectedinherited |
Used to flush the input waiting queue.
|
protectedinherited |
Used to flush any pending output data.
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
protectedinherited |
Used to initialize a newly opened serial file handle.
You should set serial properties and DTR manually before first use.
void TTYStream::interactive | ( | bool | flag | ) |
Set tty mode to buffered or "interactive".
When interactive, all streamed I/O is directly sent to the serial port immediately.
flag | bool set to true to make interactive. |
|
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. If read buffer contains data then input is ready and if write buffer contains data it is first flushed then checked.
pend | ready check to perform. |
timeout | in milliseconds. |
Reimplemented from Serial.
|
protectedinherited |
Opens the serial device.
fname | Pathname of device to open |
|
protected |
This streambuf method is used to write the output buffer through the established tty port.
ch | char to push through. |
|
protectedinherited |
Restore serial device to the original settings at time of open.
|
inherited |
Send the "break" signal.
|
inherited |
Set character size.
bits | character size to use (usually 7 or 8). |
|
inlineprotectedinherited |
Set flow control.
flow | control mode. |
|
protectedinherited |
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. |
|
protectedinherited |
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. |
|
inherited |
Set serial port speed for both input and output.
speed | to select. 0 signifies modem "hang up". |
|
inherited |
Set number of stop bits.
bits | stop bits. |
|
inline |
int TTYStream::sync | ( | void | ) |
Flushes the stream input and out buffers, writes pending output.
|
inherited |
Set the DTR mode off momentarily.
millisec | number of milliseconds. |
|
protected |
This streambuf method is used for doing unbuffered reads through the establish tty serial port when in interactive mode.
Also this method will handle proper use of buffers if not in interative mode.
|
protected |
This streambuf method is used to load the input buffer through the established tty serial port.
|
protectedinherited |
Used to wait until all output has been sent.