class Serial

base class for all serial I/O services. More...

Full nameost::Serial
Definition#include <serial.h>
Inherited bySerialPort, TTYSession, TTYStream, ttystream
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Methods

Protected Methods

Protected Members


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.

int dev

dev

[protected]

int bufsize

bufsize

[protected]

sioerror_t  Error (sioerror_t error, char *errstr = NULL)

Error

[protected]

This service is used to throw all serial errors which usually occur during the serial constructor.

Parameters:
errordefined serial error id.
errstrstring or message to optionally pass.

inline void  Error (char *errstr)

Error

[protected]

This service is used to thow application defined serial errors where the application specific error code is a string.

Parameters:
errstrstring or message to pass.

inline void  setError (bool enable)

setError

[protected]

This method is used to turn the error handler on or off for "throwing" execptions by manipulating the thrown flag.

Parameters:
trueto enable handler.

int  setPacketInput (int size, unsigned char btimer = 0)

setPacketInput

[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.

Parameters:
sizeof packet read request.
optionalinter-byte data packet timeout.

Returns: actual buffer size set.

int  setLineInput (char newline = 13, char nl1 = 0)

setLineInput

[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:
newlinecharacter.

Returns: size of conical input buffer.

void  Restore (void)

Restore

[protected]

Restore serial device to the original settings at time of open.

void  flushInput (void)

flushInput

[protected]

Used to flush the input waiting queue.

void  flushOutput (void)

flushOutput

[protected]

Used to flush any pending output data.

void  waitOutput (void)

waitOutput

[protected]

Used to wait until all output has been sent.

void  endSerial (void)

endSerial

[protected]

Used as the default destructor for ending serial I/O services. It will restore the port to it's original state.

void  initConfig (void)

initConfig

[protected]

Used to initialize a newly opened serial file handle. You should set serial properties and DTR manually before first use.

 Serial (const char *name)

Serial

[protected]

A serial object may be constructed from a named file on the file system. This named device must be "isatty()".

Parameters:
nameof file.

 Serial ()

Serial

[protected]

This allows later ttystream class to open and close a serial device.

 ~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.

Serial & operator= (const Serial &from)

operator=

Serial ports may also be duplecated by the assignment operator.

sioerror_t  setSpeed (unsigned long speed)

setSpeed

Set serial port speed for both input and output.

Parameters:
speedto select. 0 signifies modem "hang up".

Returns: 0 on success.

sioerror_t  setCharBits (int bits)

setCharBits

Set character size.

Parameters:
charactersize to use (usually 7 or 8).

Returns: 0 on success.

sioerror_t  setParity (sioparity_t parity)

setParity

Set parity mode.

Parameters:
paritymode.

Returns: 0 on success.

sioerror_t  setStopBits (int bits)

setStopBits

Set number of stop bits.

Parameters:
stopbits.

Returns: 0 on success.

sioerror_t  setFlowControl (sioflow_t flow)

setFlowControl

Set flow control.

Parameters:
flowcontrol mode.

Returns: 0 on success.

void  toggleDTR (timeout_t millisec)

toggleDTR

Set the DTR mode off momentarily.

Parameters:
numberof milliseconds.

void  sendBreak (void)

sendBreak

Send the "break" signal.

inline sioerror_t  getErrorNumber (void)

getErrorNumber

Often used by a "catch" to fetch the last error of a thrown serial.

Returns: error numbr of last sioerror_t.

inline char * getErrorString (void)

getErrorString

Often used by a "catch" to fetch the user set error string of a thrown serial.

Returns: string for error message.

inline int  getBufferSize (void)

getBufferSize

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.

bool  isPending (siopend_t pend, timeout_t timeout = TIMEOUT_INF)

isPending

[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.

Parameters:
readycheck to perform.
timeoutin milliseconds.

Returns: true if ready, false if timeout.