ost::Serial - The Serial class is used as the base for all serial I/O services under APE.
Contents
Constructor & Destructor Documentation
ost::Serial::Serial()[inline],[protected]
This allows later ttystream class to open and close a serial device.
ost::Serial::Serial(constchar*name)[protected]
A serial object may be constructed from a named file on the file system. This named device must be
'isatty()'.
Parametersname of file.
virtualost::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.
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@ostel.com
base class for all serial I/O services.
Member Data Documentation
intost::Serial::bufsize[protected]HANDLEost::Serial::dev[protected]boolost::Serial::linebufboolost::Serial::thrown
Member Enumeration Documentation
enumost::Serial::ErrorEnumeratorerrSuccesserrOpenNoTtyerrOpenFailederrSpeedInvaliderrFlowInvaliderrParityInvaliderrCharsizeInvaliderrStopbitsInvaliderrOptionInvaliderrResourceFailureerrOutputerrInputerrTimeouterrExtendedenumost::Serial::FlowEnumeratorflowNoneflowSoftflowHardflowBothenumost::Serial::ParityEnumeratorparityNoneparityOddparityEvenenumost::Serial::PendingEnumeratorpendingInputpendingOutputpendingError
Member Function Documentation
virtualintost::Serial::aRead(char*Data,constintLength)[protected],[virtual]
Reads from serial device.
ParametersData Point to character buffer to receive data. Buffers MUST be at least Length + 1 bytes in size.
LengthNumber of bytes to read.
virtualintost::Serial::aWrite(constchar*Data,constintLength)[protected],[virtual]
Writes to serial device.
ParametersData Point to character buffer containing data to write. Buffers MUST
LengthNumber of bytes to write.
voidost::Serial::close(void)[protected]
Closes the serial device.
voidost::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.
voidost::Serial::error(char*err)[inline],[protected]
This service is used to thow application defined serial errors where the application specific error code
is a string.
Parameterserr string or message to pass.
References ost::error().
Errorost::Serial::error(Errorerror,char*errstr=NULL)[protected]
This service is used to throw all serial errors which usually occur during the serial constructor.
Parameterserror defined serial error id.
errstr string or message to optionally pass.
voidost::Serial::flushInput(void)[protected]
Used to flush the input waiting queue.
voidost::Serial::flushOutput(void)[protected]
Used to flush any pending output data.
intost::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.
Errorost::Serial::getErrorNumber(void)[inline]
Often used by a 'catch' to fetch the last error of a thrown serial.
Returns
error numbr of last Error.
char*ost::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.
voidost::Serial::initConfig(void)[protected]
Used to initialize a newly opened serial file handle. You should set serial properties and DTR manually
before first use.
virtualboolost::Serial::isPending(Pendingpend,timeout_ttimeout=TIMEOUT_INF)[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.
Parameterspend ready check to perform.
timeout in milliseconds.
Reimplemented in ost::TTYStream.
voidost::Serial::open(constchar*fname)[protected]
Opens the serial device.
Parametersfname Pathname of device to open
Serial&ost::Serial::operator=(constSerial&from)Serial ports may also be duplecated by the assignment operator.
voidost::Serial::restore(void)[protected]
Restore serial device to the original settings at time of open.
voidost::Serial::sendBreak(void)
Send the 'break' signal.
Errorost::Serial::setCharBits(intbits)
Set character size.
Returns
0 on success.
Parametersbits character size to use (usually 7 or 8).
voidost::Serial::setError(boolenable)[inline],[protected]
This method is used to turn the error handler on or off for 'throwing' execptions by manipulating the
thrown flag.
Parametersenable true to enable handler.
Errorost::Serial::setFlowControl(Flowflow)
Set flow control.
Returns
0 on success.
Parametersflow control mode.
intost::Serial::setLineInput(charnewline=13,charnl1=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.
Parametersnewline newline character.
nl1 EOL2 control character.
Returns
size of conical input buffer.
intost::Serial::setPacketInput(intsize,unsignedcharbtimer=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.
Parameterssize of packet read request.
btimer optional inter-byte data packet timeout.
Errorost::Serial::setParity(Parityparity)
Set parity mode.
Returns
0 on success.
Parametersparity mode.
Errorost::Serial::setSpeed(unsignedlongspeed)
Set serial port speed for both input and output.
Returns
0 on success.
Parametersspeed to select. 0 signifies modem 'hang up'.
Errorost::Serial::setStopBits(intbits)
Set number of stop bits.
Returns
0 on success.
Parametersbits stop bits.
voidost::Serial::toggleDTR(timeout_tmillisec)
Set the DTR mode off momentarily.
Parametersmillisec number of milliseconds.
voidost::Serial::waitOutput(void)[protected]
Used to wait until all output has been sent.
Member Typedef Documentation
typedefenumErrorost::Serial::ErrortypedefenumFlowost::Serial::FlowtypedefenumParityost::Serial::ParitytypedefenumPendingost::Serial::Pending
Name
ost::Serial - The Serial class is used as the base for all serial I/O services under APE.
Synopsis
#include <serial.h>
Inherited by ost::SerialPort, and ost::TTYStream.
PublicTypes
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 ErrorError
typedef enum FlowFlow
typedef enum ParityParity
typedef enum PendingPendingPublicMemberFunctions
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.
Serial & operator= (const Serial &from)
Serial ports may also be duplecated by the assignment operator.
ErrorsetSpeed (unsigned long speed)
Set serial port speed for both input and output.
ErrorsetCharBits (int bits)
Set character size.
ErrorsetParity (Parity parity)
Set parity mode.
ErrorsetStopBits (int bits)
Set number of stop bits.
ErrorsetFlowControl (Flow flow)
Set flow control.
void toggleDTR (timeout_t millisec)
Set the DTR mode off momentarily.
void sendBreak (void)
Send the 'break' signal.
ErrorgetErrorNumber (void)
Often used by a 'catch' to fetch the last error of a thrown serial.
char * getErrorString (void)
Often used by a 'catch' to fetch the user set error string of a thrown serial.
int getBufferSize (void)
Get the 'buffer' size for buffered operations.
virtual bool isPending (Pending pend, timeout_t timeout=TIMEOUT_INF)
Get the status of pending operations.
ProtectedMemberFunctions
void open (const char *fname)
Opens the serial device.
void close (void)
Closes the serial device.
virtual int aRead (char *Data, const int Length)
Reads from serial device.
virtual int aWrite (const char *Data, const int Length)
Writes to serial device.
Errorerror (Error error, char *errstr=NULL)
This service is used to throw all serial errors which usually occur during the serial constructor.
void error (char *err)
This service is used to thow application defined serial errors where the application specific error
code is a string.
void setError (bool enable)
This method is used to turn the error handler on or off for 'throwing' execptions by manipulating the
thrown flag.
int setPacketInput (int size, unsigned char btimer=0)
Set packet read mode and 'size' of packet read buffer.
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.
void restore (void)
Restore serial device to the original settings at time of open.
void flushInput (void)
Used to flush the input waiting queue.
void flushOutput (void)
Used to flush any pending output data.
void waitOutput (void)
Used to wait until all output has been sent.
void endSerial (void)
Used as the default destructor for ending serial I/O services.
void initConfig (void)
Used to initialize a newly opened serial file handle.
Serial ()
This allows later ttystream class to open and close a serial device.
Serial (const char *name)
A serial object may be constructed from a named file on the file system.
ProtectedAttributesHANDLEdev
int bufsize