Bayonne2 / Common C++ 2 Framework
|
The serial port is an internal class which is attached to and then serviced by a specified SerialService thread. 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 | |
void | setTimer (timeout_t timeout=0) |
Derived setTimer to notify the service thread pool of changes in expected timeout. More... | |
void | incTimer (timeout_t timeout) |
Derived incTimer to notify the service thread pool of a change in expected timeout. 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... | |
virtual bool | isPending (Pending pend, timeout_t timeout=TIMEOUT_INF) |
Get the status of pending operations. More... | |
void | decTimer (timeout_t timeout) |
Adjust a timeout based on the current time reference value either from object creation or the last setTimer(). More... | |
void | sleepTimer (void) |
Sleep until the current timer expires. More... | |
void | endTimer (void) |
This is used to "disable" the service thread from expiring the timer object. More... | |
timeout_t | getTimer (void) const |
This is used by service threads to determine how much time remains before the timer expires based on a timeout specified in setTimer() or incTimer(). More... | |
timeout_t | getElapsed (void) const |
This is used to determine how much time has elapsed since a timer port setTimer benchmark time was initially set. More... | |
Protected Member Functions | |
SerialPort (SerialService *svc, const char *name) | |
Construct a tty serial port for a named serial device. More... | |
virtual | ~SerialPort () |
Disconnect the Serial Port from the service pool thread and shutdown the port. More... | |
void | setDetectPending (bool) |
Used to indicate if the service thread should monitor pending data for us. More... | |
bool | getDetectPending (void) const |
Get the current state of the DetectPending flag. More... | |
void | setDetectOutput (bool) |
Used to indicate if output ready monitoring should be performed by the service thread. More... | |
bool | getDetectOutput (void) const |
Get the current state of the DetectOutput flag. More... | |
virtual void | expired (void) |
Called by the service thread when the objects timer has expired. More... | |
virtual void | pending (void) |
Called by the service thread when input data is pending for this tty port. More... | |
virtual void | disconnect (void) |
Called by the service thread when an exception has occured such as a hangup. More... | |
int | output (void *buf, int len) |
Transmit "send" data to the serial port. More... | |
virtual void | output (void) |
Perform when output is available for sending data. More... | |
int | input (void *buf, int len) |
Receive "input" for pending data from the serial 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 | |
HANDLE | dev |
int | bufsize |
Private Attributes | |
SerialPort * | next |
SerialPort * | prev |
SerialService * | service |
bool | detect_pending |
bool | detect_output |
bool | detect_disconnect |
Friends | |
class | SerialService |
The serial port is an internal class which is attached to and then serviced by a specified SerialService thread.
Derived versions of this class offer specific functionality such as serial integration protocols.
The TTYPort and TTYService classes are used to form thread-pool serviced serial I/O protocol sets. These can be used when one has a large number of serial devices to manage, and a single (or limited number of) thread(s) can then be used to service the tty port objects present. Each tty port supports a timer control and several virtual methods that the service thread can call when events occur. This model provides for "callback" event management, whereby the service thread performs a "callback" into the port object when events occur. Specific events supported include the expiration of a TTYPort timer, pending input data waiting to be read, and "sighup" connection breaks.
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
protected |
Construct a tty serial port for a named serial device.
svc | pool thread object. |
name | of tty port. |
|
protectedvirtual |
Disconnect the Serial Port from the service pool thread and shutdown the port.
|
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.
|
inherited |
Adjust a timeout based on the current time reference value either from object creation or the last setTimer().
This reference can be used to time synchronize realtime data over specified intervals and force expiration when a new frame should be released in a synchronized manner.
timeout | delay in milliseconds from reference. |
|
protectedvirtual |
Called by the service thread when an exception has occured such as a hangup.
|
protectedinherited |
Used as the default destructor for ending serial I/O services.
It will restore the port to it's original state.
|
inherited |
This is used to "disable" the service thread from expiring the timer object.
It does not effect the reference time from either creation or a setTimer().
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 |
|
protectedvirtual |
Called by the service thread when the objects timer has expired.
|
protectedinherited |
Used to flush the input waiting queue.
|
protectedinherited |
Used to flush any pending output data.
|
inlineinherited |
|
inlineprotected |
|
inlineprotected |
|
inherited |
This is used to determine how much time has elapsed since a timer port setTimer benchmark time was initially set.
This allows one to use setTimer() to set the timer to the current time and then measure elapsed time from that point forward.
return time elapsed in milliseconds, or TIMEOUT_INF if inactive.
|
inlineinherited |
|
inlineinherited |
|
inherited |
This is used by service threads to determine how much time remains before the timer expires based on a timeout specified in setTimer() or incTimer().
It can also be called after setting a timeout with incTimer() to see if the current timeout has already expired and hence that the application is already delayed and should skip frame(s).
return time remaining in milliseconds, or TIMEOUT_INF if inactive.
void SerialPort::incTimer | ( | timeout_t | timeout | ) |
Derived incTimer to notify the service thread pool of a change in expected timeout.
This allows SerialService to reschedule all timers.
|
protectedinherited |
Used to initialize a newly opened serial file handle.
You should set serial properties and DTR manually before first use.
|
inlineprotected |
Receive "input" for pending data from the serial port.
This is not a public member since it's meant to support internal protocols rather than direct external access to the device.
buf | address of buffer to input. |
len | of input buffer used. |
|
virtualinherited |
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.
pend | ready check to perform. |
timeout | in milliseconds. |
Reimplemented in TTYStream.
|
protectedinherited |
Opens the serial device.
fname | Pathname of device to open |
|
inlineprotected |
|
protectedvirtual |
Perform when output is available for sending data.
|
protectedvirtual |
Called by the service thread when input data is pending for this tty port.
Effected by setPacketInput and by setLineInput.
|
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). |
|
protected |
Used to indicate if output ready monitoring should be performed by the service thread.
|
protected |
Used to indicate if the service thread should monitor pending data for us.
|
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. |
void SerialPort::setTimer | ( | timeout_t | timeout = 0 | ) |
Derived setTimer to notify the service thread pool of changes in expected timeout.
This allows SerialService to reschedule all timers.
timeout | in milliseconds. |
|
inherited |
Sleep until the current timer expires.
This is useful in time syncing realtime periodic tasks.
|
inherited |
Set the DTR mode off momentarily.
millisec | number of milliseconds. |
|
protectedinherited |
Used to wait until all output has been sent.
|
friend |
|
private |
|
private |
|
private |