43 #ifndef COMMONCPP_SERIAL_H_
44 #define COMMONCPP_SERIAL_H_
46 #ifndef COMMONCPP_CONFIG_H_
47 #include <commoncpp/config.h>
50 #ifndef COMMONCPP_THREAD_H_
54 #ifndef COMMMONCPP_EXCEPTION_H_
109 typedef enum Error Error;
117 typedef enum Flow Flow;
124 typedef enum Parity Parity;
131 typedef enum Pending Pending;
148 void initSerial(
void);
159 void open(
const char *fname);
174 virtual int aRead(
char * Data,
const int Length);
182 virtual int aWrite(
const char * Data,
const int Length);
191 Error error(Error error,
char *errstr = NULL);
200 {error(errExtended, err);}
210 {flags.thrown = !enable;}
222 int setPacketInput(
int size,
unsigned char btimer = 0);
233 int setLineInput(
char newline = 13,
char nl1 = 0);
243 void flushInput(
void);
248 void flushOutput(
void);
253 void waitOutput(
void);
259 void endSerial(
void);
266 void initConfig(
void);
306 Error setSpeed(
unsigned long speed);
314 Error setCharBits(
int bits);
322 Error setParity(Parity parity);
330 Error setStopBits(
int bits);
338 Error setFlowControl(Flow flow);
350 void sendBreak(
void);
389 virtual bool isPending(Pending pend,
timeout_t timeout = TIMEOUT_INF);
413 class __EXPORT
TTYStream :
protected std::streambuf,
public Serial,
public std::iostream
441 void endStream(
void);
468 int overflow(
int ch);
499 void interactive(
bool flag);
520 bool isPending(Pending pend,
timeout_t timeout = TIMEOUT_INF);
554 void open(
const char *name);
588 TTYSession(
const char *name,
int pri = 0,
int stack = 0);
631 bool detect_disconnect;
654 void setDetectPending(
bool );
660 {
return detect_pending; }
666 void setDetectOutput(
bool );
672 {
return detect_output; }
678 virtual void expired(
void);
685 virtual void pending(
void);
691 virtual void disconnect(
void);
703 {
return aWrite((
char *)buf, len);}
708 virtual void output(
void);
719 inline int input(
void *buf,
int len)
720 {
return aRead((
char *)buf, len);}
799 virtual void onUpdate(
unsigned char flag);
805 virtual void onEvent(
void);
825 void update(
unsigned char flag = 0xff);
835 SerialService(
int pri = 0,
size_t stack = 0,
const char *
id = NULL);
854 #ifdef CCXX_EXCEPTIONS
855 class __EXPORT SerException :
public IOException
858 SerException(
const String &str) : IOException(str) {}
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...
The TTYSession aggragates a TTYStream and a Common C++ Thread which is assumed to be the execution co...
void setError(bool enable)
This method is used to turn the error handler on or off for "throwing" execptions by manipulating the...
Common C++ thread class and sychronization objects.
void error(char *err)
This service is used to thow application defined serial errors where the application specific error c...
bool getDetectPending(void) const
Get the current state of the DetectPending flag.
int getCount(void)
Get current reference count.
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...
int input(void *buf, int len)
Receive "input" for pending data from the serial port.
Error getErrorNumber(void)
Often used by a "catch" to fetch the last error of a thrown serial.
int getBufferSize(void)
Get the "buffer" size for buffered operations.
Serial()
This allows later ttystream class to open and close a serial device.
int output(void *buf, int len)
Transmit "send" data to the serial port.
bool getDetectOutput(void) const
Get the current state of the DetectOutput flag.
bool operator!()
Test to see if stream is opened.
The serial port is an internal class which is attached to and then serviced by a specified SerialServ...
A more natural C++ "ttystream" class for use by non-threaded applications.
unsigned long timeout_t
Typedef for millisecond timer values.
char * getErrorString(void)
Often used by a "catch" to fetch the user set error string of a thrown serial.
The Serial class is used as the base for all serial I/O services under APE.
GNU Common C++ exception model base classes.