A more natural C++ "ttystream" class for use by non-threaded applications.
More...
#include <serial.h>
|
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 |
|
|
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...
|
|
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...
|
|
A more natural C++ "ttystream" class for use by non-threaded applications.
This class behaves a lot more like fstream and similar classes.
- Author
- David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m C++ "fstream" style ttystream class.
Definition at line 542 of file serial.h.
Enumerator |
---|
errSuccess |
|
errOpenNoTty |
|
errOpenFailed |
|
errSpeedInvalid |
|
errFlowInvalid |
|
errParityInvalid |
|
errCharsizeInvalid |
|
errStopbitsInvalid |
|
errOptionInvalid |
|
errResourceFailure |
|
errOutput |
|
errInput |
|
errTimeout |
|
errExtended |
|
Definition at line 101 of file serial.h.
Enumerator |
---|
flowNone |
|
flowSoft |
|
flowHard |
|
flowBoth |
|
Definition at line 119 of file serial.h.
Enumerator |
---|
parityNone |
|
parityOdd |
|
parityEven |
|
Definition at line 127 of file serial.h.
Enumerator |
---|
pendingInput |
|
pendingOutput |
|
pendingError |
|
Definition at line 134 of file serial.h.
Construct an unopened "ttystream" object.
ttystream::ttystream |
( |
const char * |
name | ) |
|
Construct and "open" a tty stream object.
A filename in the form "device:options[,options]" may be used to pass device options as part of the open.
- Parameters
-
name | of file and serial options. |
void TTYStream::allocate |
( |
void |
| ) |
|
|
protectedinherited |
Used to allocate the buffer space needed for iostream operations.
This is based on MAX_INPUT.
virtual int Serial::aRead |
( |
char * |
Data, |
|
|
const int |
Length |
|
) |
| |
|
protectedvirtualinherited |
Reads from serial device.
- Parameters
-
Data | Point to character buffer to receive data. Buffers MUST be at least Length + 1 bytes in size. |
Length | Number of bytes to read. |
virtual int Serial::aWrite |
( |
const char * |
Data, |
|
|
const int |
Length |
|
) |
| |
|
protectedvirtualinherited |
Writes to serial device.
- Parameters
-
Data | Point to character buffer containing data to write. Buffers MUST |
Length | Number of bytes to write. |
void ttystream::close |
( |
void |
| ) |
|
Close method for a tty stream.
void Serial::endSerial |
( |
void |
| ) |
|
|
protectedinherited |
Used as the default destructor for ending serial I/O services.
It will restore the port to it's original state.
void TTYStream::endStream |
( |
void |
| ) |
|
|
protectedinherited |
Used to terminate the buffer space and clean up the tty connection.
This function is called by the destructor.
Error Serial::error |
( |
Error |
error, |
|
|
char * |
errstr = NULL |
|
) |
| |
|
protectedinherited |
This service is used to throw all serial errors which usually occur during the serial constructor.
- Parameters
-
error | defined serial error id. |
errstr | string or message to optionally pass. |
void Serial::error |
( |
char * |
err | ) |
|
|
inlineprotectedinherited |
This service is used to thow application defined serial errors where the application specific error code is a string.
- Parameters
-
err | string or message to pass. |
Definition at line 209 of file serial.h.
void Serial::flushInput |
( |
void |
| ) |
|
|
protectedinherited |
Used to flush the input waiting queue.
void Serial::flushOutput |
( |
void |
| ) |
|
|
protectedinherited |
Used to flush any pending output data.
int Serial::getBufferSize |
( |
void |
| ) |
|
|
inlineinherited |
Get the "buffer" size for buffered operations.
This can be used when setting packet or line read modes to determine how many bytes to wait for in a given read call.
- Returns
- number of bytes used for buffering.
Definition at line 387 of file serial.h.
Error Serial::getErrorNumber |
( |
void |
| ) |
|
|
inlineinherited |
Often used by a "catch" to fetch the last error of a thrown serial.
- Returns
- error numbr of last Error.
Definition at line 368 of file serial.h.
char* Serial::getErrorString |
( |
void |
| ) |
|
|
inlineinherited |
Often used by a "catch" to fetch the user set error string of a thrown serial.
- Returns
- string for error message.
Definition at line 377 of file serial.h.
void Serial::initConfig |
( |
void |
| ) |
|
|
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 | ) |
|
|
inherited |
Set tty mode to buffered or "interactive".
When interactive, all streamed I/O is directly sent to the serial port immediately.
- Parameters
-
flag | bool set to true to make interactive. |
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.
- Returns
- true if ready, false if timeout.
- Parameters
-
pend | ready check to perform. |
timeout | in milliseconds. |
Reimplemented from Serial.
void ttystream::open |
( |
const char * |
name | ) |
|
Open method for a tty stream.
- Parameters
-
bool ttystream::operator! |
( |
| ) |
|
|
inline |
Test to see if stream is opened.
Definition at line 574 of file serial.h.
int TTYStream::overflow |
( |
int |
ch | ) |
|
|
protectedinherited |
This streambuf method is used to write the output buffer through the established tty port.
- Parameters
-
- Returns
- char pushed through.
void Serial::restore |
( |
void |
| ) |
|
|
protectedinherited |
Restore serial device to the original settings at time of open.
void Serial::sendBreak |
( |
void |
| ) |
|
|
inherited |
Error Serial::setCharBits |
( |
int |
bits | ) |
|
|
inherited |
Set character size.
- Returns
- 0 on success.
- Parameters
-
bits | character size to use (usually 7 or 8). |
void Serial::setError |
( |
bool |
enable | ) |
|
|
inlineprotectedinherited |
This method is used to turn the error handler on or off for "throwing" execptions by manipulating the thrown flag.
- Parameters
-
enable | true to enable handler. |
Definition at line 219 of file serial.h.
Set flow control.
- Returns
- 0 on success.
- Parameters
-
int Serial::setLineInput |
( |
char |
newline = 13 , |
|
|
char |
nl1 = 0 |
|
) |
| |
|
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.
- Parameters
-
newline | newline character. |
nl1 | EOL2 control character. |
- Returns
- size of conical input buffer.
int Serial::setPacketInput |
( |
int |
size, |
|
|
unsigned char |
btimer = 0 |
|
) |
| |
|
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.
- Returns
- actual buffer size set.
- Parameters
-
size | of packet read request. |
btimer | optional inter-byte data packet timeout. |
Set parity mode.
- Returns
- 0 on success.
- Parameters
-
Error Serial::setSpeed |
( |
unsigned long |
speed | ) |
|
|
inherited |
Set serial port speed for both input and output.
- Returns
- 0 on success.
- Parameters
-
speed | to select. 0 signifies modem "hang up". |
Error Serial::setStopBits |
( |
int |
bits | ) |
|
|
inherited |
Set number of stop bits.
- Returns
- 0 on success.
- Parameters
-
Set the timeout control.
- Parameters
-
Definition at line 499 of file serial.h.
int TTYStream::sync |
( |
void |
| ) |
|
|
inherited |
Flushes the stream input and out buffers, writes pending output.
- Returns
- 0 on success.
Set the DTR mode off momentarily.
- Parameters
-
millisec | number of milliseconds. |
int TTYStream::uflow |
( |
void |
| ) |
|
|
protectedinherited |
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.
- Returns
- char from tty serial port, EOF also possible.
int TTYStream::underflow |
( |
void |
| ) |
|
|
protectedinherited |
This streambuf method is used to load the input buffer through the established tty serial port.
- Returns
- char from get buffer, EOF also possible.
void Serial::waitOutput |
( |
void |
| ) |
|
|
protectedinherited |
Used to wait until all output has been sent.
The documentation for this class was generated from the following file: