Go to the documentation of this file.
44 #ifndef COMMONCPP_SERIAL_H_
45 #define COMMONCPP_SERIAL_H_
47 #ifndef COMMONCPP_CONFIG_H_
48 #include <commoncpp/config.h>
51 #ifndef COMMONCPP_THREAD_H_
55 #ifndef COMMMONCPP_EXCEPTION_H_
110 typedef enum Error Error;
118 typedef enum Flow Flow;
125 typedef enum Parity Parity;
132 typedef enum Pending Pending;
149 void initSerial(
void);
175 virtual int aRead(
char * Data,
const int Length);
183 virtual int aWrite(
const char * Data,
const int Length);
192 Error
error(Error error,
char *errstr = NULL);
201 error(errExtended, err);
212 flags.thrown = !enable;
396 virtual bool isPending(Pending pend, timeout_t timeout = TIMEOUT_INF);
420 class __EXPORT
TTYStream :
protected std::streambuf,
public Serial,
public std::iostream
530 bool isPending(Pending pend, timeout_t timeout = TIMEOUT_INF) __OVERRIDE;
648 bool detect_disconnect;
679 return detect_pending;
692 return detect_output;
724 return aWrite((
char *)buf, len);
741 inline int input(
void *buf,
int len) {
742 return aRead((
char *)buf, len);
813 void run(
void) __OVERRIDE;
880 #ifdef CCXX_EXCEPTIONS
881 class __EXPORT SerException :
public IOException
884 SerException(
const String &str) : IOException(str) {}
void setTimeout(timeout_t to)
Set the timeout control.
int output(void *buf, int len)
Transmit "send" data to the serial port.
int overflow(int ch)
This streambuf method is used to write the output buffer through the established tty port.
virtual ~TTYStream()
End the tty stream and cleanup.
bool getDetectOutput(void) const
Get the current state of the DetectOutput flag.
void setDetectOutput(bool)
Used to indicate if output ready monitoring should be performed by the service thread.
virtual ~SerialService()
Terminate the service thread and update attached objects.
virtual int aRead(char *Data, const int Length)
Reads from serial device.
int sync(void)
Flushes the stream input and out buffers, writes pending output.
Error error(Error error, char *errstr=NULL)
This service is used to throw all serial errors which usually occur during the serial constructor.
void open(const char *fname)
Opens the serial device.
Error setStopBits(int bits)
Set number of stop bits.
void close(void)
Close method for a tty stream.
ttystream(const char *name)
Construct and "open" a tty stream object.
int setPacketInput(int size, uint8_t btimer=0)
Set packet read mode and "size" of packet read buffer.
void flushOutput(void)
Used to flush any pending output data.
bool operator!()
Test to see if stream is opened.
ttystream()
Construct an unopened "ttystream" object.
Serial()
This allows later ttystream class to open and close a serial device.
TTYStream(const char *filename, timeout_t to=0)
Create and open a tty serial port.
void endStream(void)
Used to terminate the buffer space and clean up the tty connection.
int uflow(void)
This streambuf method is used for doing unbuffered reads through the establish tty serial port when i...
virtual void onEvent(void)
A virtual handler for event loop calls.
Common C++ thread class and sychronization objects.
Error setSpeed(unsigned long speed)
Set serial port speed for both input and output.
void initConfig(void)
Used to initialize a newly opened serial file handle.
void endSerial(void)
Used as the default destructor for ending serial I/O services.
void close(void)
Closes the serial device.
void restore(void)
Restore serial device to the original settings at time of open.
void interactive(bool flag)
Set tty mode to buffered or "interactive".
void update(uint8_t flag=0xff)
Notify service thread that a port has been added or removed, or a timer changed, so that a new schedu...
SerialService(int pri=0, size_t stack=0, const char *id=NULL)
Create a service thread for attaching serial ports.
TTYStream()
This constructor is used to derive "ttystream", a more C++ style version of the TTYStream class.
void setDetectPending(bool)
Used to indicate if the service thread should monitor pending data for us.
Error setParity(Parity parity)
Set parity mode.
TTYSession(const char *name, int pri=0, int stack=0)
Create TTY stream that will be managed by it's own thread.
int setLineInput(char newline=13, char nl1=0)
Set "line buffering" read mode and specifies the newline character to be used in seperating line reco...
virtual void pending(void)
Called by the service thread when input data is pending for this tty port.
Timer ports are used to provide synchronized timing events when managed under a "service thread" such...
A more natural C++ "ttystream" class for use by non-threaded applications.
virtual void disconnect(void)
Called by the service thread when an exception has occured such as a hangup.
void toggleDTR(timeout_t millisec)
Set the DTR mode off momentarily.
Error setFlowControl(Flow flow)
Set flow control.
virtual void output(void)
Perform when output is available for sending data.
AppLog & error(AppLog &sl)
Manipulator for error level.
virtual void onCallback(SerialPort *port)
A virtual handler for adding support for additional callback events into SerialPort.
void open(const char *name)
Open method for a tty stream.
void error(char *err)
This service is used to thow application defined serial errors where the application specific error c...
void setError(bool enable)
This method is used to turn the error handler on or off for "throwing" execptions by manipulating the...
virtual void expired(void)
Called by the service thread when the objects timer has expired.
int getCount(void) const
Get current reference count.
bool isPending(Pending pend, timeout_t timeout=ucommon::Timer::inf)
Get the status of pending operations.
virtual ~Serial()
The serial base class may be "thrown" as a result on an error, and the "catcher" may then choose to d...
SerialPort(SerialService *svc, const char *name)
Construct a tty serial port for a named serial device.
virtual void onUpdate(uint8_t flag)
A virtual handler for processing user defined update requests (1-254) which have been posted through ...
void setTimer(timeout_t timeout=0)
Derived setTimer to notify the service thread pool of changes in expected timeout.
bool getDetectPending(void) const
Get the current state of the DetectPending flag.
virtual int aWrite(const char *Data, const int Length)
Writes to serial device.
void allocate(void)
Used to allocate the buffer space needed for iostream operations.
Serial(const char *name)
A serial object may be constructed from a named file on the file system.
The serial port is an internal class which is attached to and then serviced by a specified SerialServ...
int getBufferSize(void) const
Get the "buffer" size for buffered operations.
virtual ~SerialPort()
Disconnect the Serial Port from the service pool thread and shutdown the port.
TTY streams are used to represent serial connections that are fully "streamable" objects using C++ st...
void sendBreak(void)
Send the "break" signal.
int underflow(void)
This streambuf method is used to load the input buffer through the established tty serial port.
The SerialService is a thead service object that is meant to service attached serial ports.
void incTimer(timeout_t timeout)
Derived incTimer to notify the service thread pool of a change in expected timeout.
virtual bool isPending(Pending pend, timeout_t timeout=ucommon::Timer::inf)
Get the status of pending operations.
The Serial class is used as the base for all serial I/O services under APE.
void waitOutput(void)
Used to wait until all output has been sent.
Error setCharBits(int bits)
Set character size.
The TTYSession aggragates a TTYStream and a Common C++ Thread which is assumed to be the execution co...
GNU Common C++ exception model base classes.
Error getErrorNumber(void) const
Often used by a "catch" to fetch the last error of a thrown serial.
void flushInput(void)
Used to flush the input waiting queue.
char * getErrorString(void) const
Often used by a "catch" to fetch the user set error string of a thrown serial.
int input(void *buf, int len)
Receive "input" for pending data from the serial port.
Serial & operator=(const Serial &from)
Serial ports may also be duplecated by the assignment operator.