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);
162 void open(
const char *fname);
177 virtual int aRead(
char * Data,
const int Length);
185 virtual int aWrite(
const char * Data,
const int Length);
194 Error error(Error error,
char *errstr = NULL);
203 {error(errExtended, err);};
213 {flags.thrown = !enable;};
225 int setPacketInput(
int size,
unsigned char 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);
309 Error setSpeed(
unsigned long speed);
317 Error setCharBits(
int bits);
325 Error setParity(Parity parity);
333 Error setStopBits(
int bits);
341 Error setFlowControl(Flow flow);
353 void sendBreak(
void);
392 virtual bool isPending(Pending pend,
timeout_t timeout = TIMEOUT_INF);
416 class __EXPORT
TTYStream :
protected std::streambuf,
public Serial,
public std::iostream
444 void endStream(
void);
471 int overflow(
int ch);
502 void interactive(
bool flag);
557 void open(
const char *name);
591 TTYSession(
const char *name,
int pri = 0,
int stack = 0);
634 bool detect_disconnect;
657 void setDetectPending(
bool );
663 {
return detect_pending; }
669 void setDetectOutput(
bool );
675 {
return detect_output; }
681 virtual void expired(
void);
688 virtual void pending(
void);
694 virtual void disconnect(
void);
706 {
return aWrite((
char *)buf, len);};
711 virtual void output(
void);
722 inline int input(
void *buf,
int len)
723 {
return aRead((
char *)buf, len);};
801 virtual void onUpdate(
unsigned char flag);
807 virtual void onEvent(
void);
827 void update(
unsigned char flag = 0xff);
837 SerialService(
int pri = 0,
size_t stack = 0,
const char *
id = NULL);
856 #ifdef CCXX_EXCEPTIONS
857 class __EXPORT SerException :
public IOException
860 SerException(
const String &str) : IOException(str) {};
TTY streams are used to represent serial connections that are fully "streamable" objects using C++ st...
void setError(bool enable)
This method is used to turn the error handler on or off for "throwing" execptions by manipulating the...
void setTimeout(timeout_t to)
Set the timeout control.
void error(char *err)
This service is used to thow application defined serial errors where the application specific error c...
void open(const char *fname)
Opens the serial device.
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...
virtual int aRead(char *Data, const int Length)
Reads from serial device.
The TTYSession aggragates a TTYStream and a Common C++ Thread which is assumed to be the execution co...
int input(void *buf, int len)
Receive "input" for pending data from the serial port.
Common C++ thread class and sychronization objects.
void setTimer(timeout_t timeout=0)
Set a new start time for the object based on when this call is made and optionally activate the timer...
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.
void incTimer(timeout_t timeout)
Set a timeout based on the current time reference value either from object creation or the last setTi...
unsigned long timeout_t
Typedef for millisecond timer values.
virtual bool isPending(Pending pend, timeout_t timeout=ucommon::Timer::inf)
Get the status of pending 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.
GNU Common C++ exception model base classes.
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...
virtual int aWrite(const char *Data, const int Length)
Writes to serial device.
Timer ports are used to provide synchronized timing events when managed under a "service thread" such...
void close(void)
Closes the serial device.
A more natural C++ "ttystream" class for use by non-threaded applications.
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.