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);}
211 {flags.thrown = !enable;}
223 int setPacketInput(
int size,
unsigned char btimer = 0);
234 int setLineInput(
char newline = 13,
char nl1 = 0);
244 void flushInput(
void);
249 void flushOutput(
void);
254 void waitOutput(
void);
260 void endSerial(
void);
267 void initConfig(
void);
307 Error setSpeed(
unsigned long speed);
315 Error setCharBits(
int bits);
323 Error setParity(Parity parity);
331 Error setStopBits(
int bits);
339 Error setFlowControl(Flow flow);
346 void toggleDTR(timeout_t millisec);
351 void sendBreak(
void);
390 virtual bool isPending(Pending pend, timeout_t timeout = TIMEOUT_INF);
414 class __EXPORT
TTYStream :
protected std::streambuf,
public Serial,
public std::iostream
442 void endStream(
void);
469 int overflow(
int ch);
478 TTYStream(
const char *filename, timeout_t to = 0);
500 void interactive(
bool flag);
521 bool isPending(Pending pend, timeout_t timeout = TIMEOUT_INF);
555 void open(
const char *name);
589 TTYSession(
const char *name,
int pri = 0,
int stack = 0);
632 bool detect_disconnect;
655 void setDetectPending(
bool );
661 {
return detect_pending; }
667 void setDetectOutput(
bool );
673 {
return detect_output; }
679 virtual void expired(
void);
686 virtual void pending(
void);
692 virtual void disconnect(
void);
704 {
return aWrite((
char *)buf, len);}
709 virtual void output(
void);
720 inline int input(
void *buf,
int len)
721 {
return aRead((
char *)buf, len);}
731 void setTimer(timeout_t timeout = 0);
738 void incTimer(timeout_t timeout);
800 virtual void onUpdate(
unsigned char flag);
806 virtual void onEvent(
void);
826 void update(
unsigned char flag = 0xff);
836 SerialService(
int pri = 0,
size_t stack = 0,
const char *
id = NULL);
855 #ifdef CCXX_EXCEPTIONS
856 class __EXPORT SerException :
public IOException
859 SerException(
const String &str) : IOException(str) {}
A more natural C++ "ttystream" class for use by non-threaded applications.
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...
void error(char *err)
This service is used to thow application defined serial errors where the application specific error c...
bool operator!()
Test to see if stream is opened.
bool getDetectPending(void) const
Get the current state of the DetectPending flag.
int getCount(void)
Get current reference count.
void setTimeout(timeout_t to)
Set the timeout control.
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.
The serial port is an internal class which is attached to and then serviced by a specified SerialServ...
TTY streams are used to represent serial connections that are fully "streamable" objects using C++ st...
Common C++ thread class and sychronization objects.
GNU Common C++ exception model base classes.
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.