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);
161 void open(
const char *fname);
176 virtual int aRead(
char * Data,
const int Length);
184 virtual int aWrite(
const char * Data,
const int Length);
193 Error error(Error error,
char *errstr = NULL);
202 {error(errExtended, err);};
212 {flags.thrown = !enable;};
224 int setPacketInput(
int size,
unsigned char btimer = 0);
235 int setLineInput(
char newline = 13,
char nl1 = 0);
245 void flushInput(
void);
250 void flushOutput(
void);
255 void waitOutput(
void);
261 void endSerial(
void);
268 void initConfig(
void);
308 Error setSpeed(
unsigned long speed);
316 Error setCharBits(
int bits);
324 Error setParity(Parity parity);
332 Error setStopBits(
int bits);
340 Error setFlowControl(Flow flow);
352 void sendBreak(
void);
391 virtual bool isPending(Pending pend,
timeout_t timeout = TIMEOUT_INF);
415 class __EXPORT
TTYStream :
protected std::streambuf,
public Serial,
public std::iostream
443 void endStream(
void);
470 int overflow(
int ch);
501 void interactive(
bool flag);
556 void open(
const char *name);
590 TTYSession(
const char *name,
int pri = 0,
int stack = 0);
633 bool detect_disconnect;
656 void setDetectPending(
bool );
662 {
return detect_pending; }
668 void setDetectOutput(
bool );
674 {
return detect_output; }
680 virtual void expired(
void);
687 virtual void pending(
void);
693 virtual void disconnect(
void);
705 {
return aWrite((
char *)buf, len);};
710 virtual void output(
void);
721 inline int input(
void *buf,
int len)
722 {
return aRead((
char *)buf, len);};
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) {};
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...
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...
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...
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.
GNU Common C++ exception model base classes.
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.
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.
Common C++ thread class and sychronization objects.
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.
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.
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.
unsigned long timeout_t
Typedef for millisecond timer values.
void close(void)
Closes the serial device.
void incTimer(timeout_t timeout)
Set a timeout based on the current time reference value either from object creation or the last setTi...
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.