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);
160 void open(
const char *fname);
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;
225 int setPacketInput(
int size, uint8_t btimer = 0);
236 int setLineInput(
char newline = 13,
char nl1 = 0);
246 void flushInput(
void);
251 void flushOutput(
void);
256 void waitOutput(
void);
262 void endSerial(
void);
269 void initConfig(
void);
310 Error setSpeed(
unsigned long speed);
318 Error setCharBits(
int bits);
326 Error setParity(Parity parity);
334 Error setStopBits(
int bits);
342 Error setFlowControl(Flow flow);
349 void toggleDTR(timeout_t millisec);
354 void sendBreak(
void);
396 virtual bool isPending(Pending pend, timeout_t timeout = TIMEOUT_INF);
420 class __EXPORT
TTYStream :
protected std::streambuf,
public Serial,
public std::iostream
450 void endStream(
void);
458 int underflow(
void) __OVERRIDE;
468 int uflow(
void) __OVERRIDE;
477 int overflow(
int ch) __OVERRIDE;
486 TTYStream(
const char *filename, timeout_t to = 0);
509 void interactive(
bool flag);
530 bool isPending(Pending pend, timeout_t timeout = TIMEOUT_INF) __OVERRIDE;
567 void open(
const char *name);
605 TTYSession(
const char *name,
int pri = 0,
int stack = 0);
648 bool detect_disconnect;
673 void setDetectPending(
bool );
679 return detect_pending;
686 void setDetectOutput(
bool );
692 return detect_output;
699 virtual void expired(
void);
706 virtual void pending(
void);
712 virtual void disconnect(
void);
724 return aWrite((
char *)buf, len);
730 virtual void output(
void);
741 inline int input(
void *buf,
int len) {
742 return aRead((
char *)buf, len);
753 void setTimer(timeout_t timeout = 0);
760 void incTimer(timeout_t timeout);
813 void run(
void) __OVERRIDE;
824 virtual void onUpdate(uint8_t flag);
830 virtual void onEvent(
void);
850 void update(uint8_t flag = 0xff);
860 SerialService(
int pri = 0,
size_t stack = 0,
const char *
id = NULL);
880 #ifdef CCXX_EXCEPTIONS 881 class __EXPORT SerException :
public IOException
884 SerException(
const String &str) : IOException(str) {}
The serial port is an internal class which is attached to and then serviced by a specified SerialServ...
void setTimeout(timeout_t to)
Set the timeout control.
TTY streams are used to represent serial connections that are fully "streamable" objects using C++ st...
Common C++ thread class and sychronization objects.
int input(void *buf, int len)
Receive "input" for pending data from the serial port.
The TTYSession aggragates a TTYStream and a Common C++ Thread which is assumed to be the execution co...
Error getErrorNumber(void) const
Often used by a "catch" to fetch the last error of a thrown serial.
AppLog & error(AppLog &sl)
Manipulator for error level.
bool getDetectPending(void) const
Get the current state of the DetectPending flag.
char * getErrorString(void) const
Often used by a "catch" to fetch the user set error string of a thrown serial.
The SerialService is a thead service object that is meant to service attached serial ports.
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.
void setError(bool enable)
This method is used to turn the error handler on or off for "throwing" execptions by manipulating the...
bool operator!()
Test to see if stream is opened.
int getCount(void) const
Get current reference count.
Serial()
This allows later ttystream class to open and close a serial device.
bool getDetectOutput(void) const
Get the current state of the DetectOutput flag.
int getBufferSize(void) const
Get the "buffer" size for buffered operations.
The Serial class is used as the base for all serial I/O services under APE.
GNU Common C++ exception model base classes.
int output(void *buf, int len)
Transmit "send" data to the serial port.
void error(char *err)
This service is used to thow application defined serial errors where the application specific error c...