The Serial class is used as the base for all serial I/O services under APE.
More...
#include <serial.h>
Inheritance diagram for Serial:
Collaboration diagram for Serial:
Public Types
enum
Error {
errSuccess = 0,
errOpenNoTty,
errOpenFailed,
errSpeedInvalid,
errFlowInvalid,
errParityInvalid,
errCharsizeInvalid,
errStopbitsInvalid,
errOptionInvalid,
errResourceFailure,
errOutput,
errInput,
errTimeout,
errExtended
}
Public Member Functions
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 ports may also be duplecated by the assignment operator.
More...
Set serial port speed for both input and output.
More...
Set the DTR mode off momentarily.
More...
Often used by a "catch" to fetch the last error of a thrown serial.
More...
Often used by a "catch" to fetch the user set error string of a thrown serial.
More...
Get the "buffer" size for buffered operations.
More...
Get the status of pending operations.
More...
Protected Member Functions
void
open (const char *fname)
virtual int
aRead (char *Data, const int Length)
virtual int
aWrite (const char *Data, const int Length)
This service is used to throw all serial errors which usually occur during the serial constructor.
More...
This service is used to thow application defined serial errors where the application specific error code is a string.
More...
This method is used to turn the error handler on or off for "throwing" execptions by manipulating the thrown flag.
More...
Set packet read mode and "size" of packet read buffer.
More...
Set "line buffering" read mode and specifies the newline character to be used in seperating line records.
More...
Restore serial device to the original settings at time of open.
More...
Used to flush the input waiting queue.
More...
Used to flush any pending output data.
More...
Used to wait until all output has been sent.
More...
Used as the default destructor for ending serial I/O services.
More...
Used to initialize a newly opened serial file handle.
More...
This allows later ttystream class to open and close a serial device.
More...
A serial object may be constructed from a named file on the file system.
More...
Protected Attributes
Private Member Functions
Used to properly initialize serial object.
More...
Private Attributes
struct {
Detailed Description
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.
- Author
- David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m base class for all serial I/O services.
Definition at line 98 of file serial.h.
Member Typedef Documentation
Member Enumeration Documentation
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.
Constructor & Destructor Documentation
Serial::Serial
(
)
inlineprotected |
This allows later ttystream class to open and close a serial device.
Definition at line 282 of file serial.h.
Serial::Serial
(
const char *
name )
protected |
A serial object may be constructed from a named file on the file system.
This named device must be "isatty()".
- Parameters
-
name of file.
virtual Serial::~Serial
(
)
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.
Member Function Documentation
virtual int Serial::aRead
(
char *
Data,
const int
Length
)
protectedvirtual |
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
)
protectedvirtual |
Writes to serial device.
- Parameters
-
Data Point to character buffer containing data to write. Buffers MUST
Length
Number of bytes to write.
void Serial::close
(
void
)
protected |
Closes the serial device.
void Serial::endSerial
(
void
)
protected |
Used as the default destructor for ending serial I/O services.
It will restore the port to it's original state.
char *
errstr = NULL
)
protected |
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 )
inlineprotected |
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
)
protected |
Used to flush the input waiting queue.
void Serial::flushOutput
(
void
)
protected |
Used to flush any pending output data.
int Serial::getBufferSize
(
void
)
inline |
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
)
inline |
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
)
inline |
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
)
protected |
Used to initialize a newly opened serial file handle.
You should set serial properties and DTR manually before first use.
void Serial::initSerial
(
void
)
private |
Used to properly initialize serial object.
virtual bool Serial::isPending
(
Pending
pend,
)
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.
- Returns
- true if ready, false if timeout.
- Parameters
-
pend ready check to perform.
timeout in milliseconds.
Reimplemented in TTYStream.
void Serial::open
(
const char *
fname )
protected |
Opens the serial device.
- Parameters
-
fname Pathname of device to open
Serial ports may also be duplecated by the assignment operator.
void Serial::restore
(
void
)
protected |
Restore serial device to the original settings at time of open.
void Serial::sendBreak
(
void
)
Error Serial::setCharBits
(
int
bits )
Set character size.
- Returns
- 0 on success.
- Parameters
-
bits character size to use (usually 7 or 8).
void Serial::setError
(
bool
enable )
inlineprotected |
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
-
flow control mode.
int Serial::setLineInput
(
char
newline = 13
,
char
nl1 = 0
)
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.
- Parameters
-
newline newline character.
nl1 EOL2 control character.
- Returns
- size of conical input buffer.
int Serial::setPacketInput
(
int
size,
unsigned char
btimer = 0
)
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.
- 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
-
parity mode.
Error Serial::setSpeed
(
unsigned long
speed )
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 )
Set number of stop bits.
- Returns
- 0 on success.
- Parameters
-
bits stop bits.
void Serial::toggleDTR
(
timeout_t
millisec )
Set the DTR mode off momentarily.
- Parameters
-
millisec number of milliseconds.
void Serial::waitOutput
(
void
)
protected |
Used to wait until all output has been sent.
Field Documentation
int Serial::bufsize
protected |
void* Serial::current
private |
char* Serial::errstr
private |
struct { ... } Serial::flags
void* Serial::original
private |
The documentation for this class was generated from the following file:
Generated on Dec 21, 2017 for
commoncpp2-1.8.1,
ccrtp-1.7.2,
libzrtpcpp-2.3.4,
ccscript3-1.1.7,
ccaudio2-1.0.0 and
bayonne2-2.3.2
(after installation in /usr/local/)
by
doxygen 1.8.6