Go to the documentation of this file.
44 #ifndef CCXX_SERIAL_H_
45 #define CCXX_SERIAL_H_
47 #ifndef CCXX_MISSING_H_
51 #ifndef CCXX_THREAD_H_
55 #ifndef CCXX_EXCEPTION_H_
61 #define INVALID_HANDLE_VALUE (-1)
64 #ifdef CCXX_NAMESPACES
117 typedef enum Error Error;
125 typedef enum Flow Flow;
132 typedef enum Parity Parity;
139 typedef enum Pending Pending;
156 void initSerial(
void);
184 virtual int aRead(
char * Data,
const int Length);
192 virtual int aWrite(
const char * Data,
const int Length);
210 {
error(errExtended, err);};
220 {flags.thrown = !enable;};
641 bool detect_disconnect;
670 {
return detect_pending; }
682 {
return detect_output; }
713 {
return aWrite((
char *)buf, len);};
729 inline int input(
void *buf,
int len)
730 {
return aRead((
char *)buf, len);};
865 #ifdef COMMON_STD_EXCEPTION
866 class __EXPORT SerException :
public IOException
869 SerException(
const String &str) : IOException(str) {};
873 #ifdef CCXX_NAMESPACES
int bufsize
Definition: serial.h:162
@ flowHard
Definition: serial.h:122
Error error(Error error, char *errstr=NULL)
This service is used to throw all serial errors which usually occur during the serial constructor.
@ errInput
Definition: serial.h:113
The serial port is an internal class which is attached to and then serviced by a specified SerialServ...
Definition: serial.h:632
int overflow(int ch)
This streambuf method is used to write the output buffer through the established tty port.
SerialPort(SerialService *svc, const char *name)
Construct a tty serial port for a named serial device.
@ flowSoft
Definition: serial.h:121
int sync(void)
Flushes the stream input and out buffers, writes pending output.
void setTimer(timeout_t timeout=0)
Derived setTimer to notify the service thread pool of changes in expected timeout.
virtual ~SerialPort()
Disconnect the Serial Port from the service pool thread and shutdown the port.
@ errOutput
Definition: serial.h:112
@ errOpenNoTty
Definition: serial.h:103
Every thread of execution in an application is created by instantiating an object of a class derived ...
Definition: thread.h:1094
@ parityNone
Definition: serial.h:128
void flushOutput(void)
Used to flush any pending output data.
unsigned long timeout_t
Definition: thread.h:74
Error setParity(Parity parity)
Set parity mode.
void endSerial(void)
Used as the default destructor for ending serial I/O services.
@ errCharsizeInvalid
Definition: serial.h:108
void close(void)
Close method for a tty stream.
int HANDLE
Definition: serial.h:60
virtual void expired(void)
Called by the service thread when the objects timer has expired.
virtual ~Serial()
The serial base class may be "thrown" as a result on an error, and the "catcher" may then choose to d...
int underflow(void)
This streambuf method is used to load the input buffer through the established tty serial port.
void open(const char *fname)
Opens the serial device.
virtual void disconnect(void)
Called by the service thread when an exception has occured such as a hangup.
The Mutex class is used to protect a section of code so that at any given time only a single thread c...
Definition: thread.h:187
bool thrown
Definition: serial.h:146
@ errOpenFailed
Definition: serial.h:104
bool getDetectOutput(void) const
Get the current state of the DetectOutput flag.
Definition: serial.h:681
@ errStopbitsInvalid
Definition: serial.h:109
char * getErrorString(void)
Often used by a "catch" to fetch the user set error string of a thrown serial.
Definition: serial.h:377
int getCount(void)
Get current reference count.
Definition: serial.h:857
Error
Definition: serial.h:101
__EXPORT AppLog & error(AppLog &sl)
Manipulator for error level.
Definition: applog.h:541
The Serial class is used as the base for all serial I/O services under APE.
Definition: serial.h:99
friend TTYStream & lfcr(TTYStream &)
void open(const char *name)
Open method for a tty stream.
TTYSession(const char *name, int pri=0, int stack=0)
Create TTY stream that will be managed by it's own thread.
@ errSpeedInvalid
Definition: serial.h:105
virtual void output(void)
Perform when output is available for sending data.
Parity
Definition: serial.h:127
A more natural C++ "ttystream" class for use by non-threaded applications.
Definition: serial.h:543
@ parityOdd
Definition: serial.h:129
void setTimeout(timeout_t to)
Set the timeout control.
Definition: serial.h:499
void setError(bool enable)
This method is used to turn the error handler on or off for "throwing" execptions by manipulating the...
Definition: serial.h:219
ttystream(const char *name)
Construct and "open" a tty stream object.
bool linebuf
Definition: serial.h:147
virtual ~SerialService()
Terminate the service thread and update attached objects.
bool getDetectPending(void) const
Get the current state of the DetectPending flag.
Definition: serial.h:669
TTY streams are used to represent serial connections that are fully "streamable" objects using C++ st...
Definition: serial.h:424
Pending
Definition: serial.h:134
void sendBreak(void)
Send the "break" signal.
Error getErrorNumber(void)
Often used by a "catch" to fetch the last error of a thrown serial.
Definition: serial.h:368
virtual void onUpdate(unsigned char flag)
A virtual handler for processing user defined update requests (1-254) which have been posted through ...
Error setCharBits(int bits)
Set character size.
#define __EXPORT
Definition: config.h:979
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 allocate(void)
Used to allocate the buffer space needed for iostream operations.
@ flowNone
Definition: serial.h:120
int output(void *buf, int len)
Transmit "send" data to the serial port.
Definition: serial.h:712
TTYStream(const char *filename, timeout_t to=0)
Create and open a tty serial port.
void toggleDTR(timeout_t millisec)
Set the DTR mode off momentarily.
void incTimer(timeout_t timeout)
Derived incTimer to notify the service thread pool of a change in expected timeout.
int getBufferSize(void)
Get the "buffer" size for buffered operations.
Definition: serial.h:387
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...
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.
Serial()
This allows later ttystream class to open and close a serial device.
Definition: serial.h:282
Flow
Definition: serial.h:119
void error(char *err)
This service is used to thow application defined serial errors where the application specific error c...
Definition: serial.h:209
virtual int aRead(char *Data, const int Length)
Reads from serial device.
@ errResourceFailure
Definition: serial.h:111
void setDetectPending(bool)
Used to indicate if the service thread should monitor pending data for us.
Serial & operator=(const Serial &from)
Serial ports may also be duplecated by the assignment operator.
@ pendingInput
Definition: serial.h:135
@ pendingOutput
Definition: serial.h:136
Error setStopBits(int bits)
Set number of stop bits.
substitute functions which may be missing in target platform libc.
void interactive(bool flag)
Set tty mode to buffered or "interactive".
void update(unsigned char flag=0xff)
Notify service thread that a port has been added or removed, or a timer changed, so that a new schedu...
HANDLE dev
Definition: serial.h:160
int uflow(void)
This streambuf method is used for doing unbuffered reads through the establish tty serial port when i...
@ errOptionInvalid
Definition: serial.h:110
@ errParityInvalid
Definition: serial.h:107
bool isPending(Pending pend, timeout_t timeout=TIMEOUT_INF)
Get the status of pending operations.
bool operator!()
Test to see if stream is opened.
Definition: serial.h:574
int setPacketInput(int size, unsigned char btimer=0)
Set packet read mode and "size" of packet read buffer.
@ errTimeout
Definition: serial.h:114
void setDetectOutput(bool)
Used to indicate if output ready monitoring should be performed by the service thread.
The TTYSession aggragates a TTYStream and a Common C++ Thread which is assumed to be the execution co...
Definition: serial.h:589
virtual int aWrite(const char *Data, const int Length)
Writes to serial device.
void waitOutput(void)
Used to wait until all output has been sent.
virtual void onCallback(SerialPort *port)
A virtual handler for adding support for additional callback events into SerialPort.
int input(void *buf, int len)
Receive "input" for pending data from the serial port.
Definition: serial.h:729
GNU Common C++ exception model base classes.
virtual ~TTYStream()
End the tty stream and cleanup.
Error setSpeed(unsigned long speed)
Set serial port speed for both input and output.
Serial(const char *name)
A serial object may be constructed from a named file on the file system.
Timer ports are used to provide synchronized timing events when managed under a "service thread" such...
Definition: thread.h:1760
The SerialService is a thead service object that is meant to service attached serial ports.
Definition: serial.h:772
void close(void)
Closes the serial device.
@ errFlowInvalid
Definition: serial.h:106
void initConfig(void)
Used to initialize a newly opened serial file handle.
virtual void pending(void)
Called by the service thread when input data is pending for this tty port.
Synchronization and threading services.
ttystream()
Construct an unopened "ttystream" object.
friend TTYStream & crlf(TTYStream &)
timeout_t timeout
Definition: serial.h:433
virtual bool isPending(Pending pend, timeout_t timeout=TIMEOUT_INF)
Get the status of pending operations.
Error setFlowControl(Flow flow)
Set flow control.
void endStream(void)
Used to terminate the buffer space and clean up the tty connection.
char * pbuf
Definition: serial.h:432
#define TIMEOUT_INF
Definition: thread.h:115
virtual void onEvent(void)
A virtual handler for event loop calls.