00001
00035 #ifndef SERIAL_INCLUDED
00036 #define SERIAL_INCLUDED
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include <sigc++/signal_system.h>
00046 #include <termios.h>
00047 #include <unistd.h>
00048
00049 #include <string>
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 namespace Async
00083 {
00084
00085
00086
00087
00088
00089
00090
00091
00092 class FdWatch;
00093 class SerialDevice;
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00129 class Serial : public SigC::Object
00130 {
00131 public:
00135 typedef enum
00136 {
00137 PARITY_NONE,
00138 PARITY_EVEN,
00139 PARITY_ODD
00140 } Parity;
00141
00145 typedef enum
00146 {
00147 FLOW_NONE,
00148 FLOW_HW,
00149 FLOW_XONOFF
00150 } Flow;
00151
00155 typedef enum
00156 {
00157 PIN_NONE,
00158 PIN_RTS,
00159 PIN_DTR,
00160 PIN_CTS,
00161 PIN_DSR,
00162 PIN_DCD,
00163 PIN_RI
00164 } Pin;
00165
00169 static const int READ_BUFSIZE = 1024;
00170
00171
00176 Serial(const std::string& serial_port);
00177
00181 ~Serial(void);
00182
00199 bool setParams(int speed, Parity parity, int bits, int stop_bits,
00200 Flow flow);
00201
00212 bool open(void);
00213
00223 bool close(void);
00224
00233 int write(const char *buf, size_t count)
00234 {
00235 return ::write(fd, buf, count);
00236 }
00237
00254 bool setCanonical(bool canonical);
00255
00266 bool stopInput(bool stop);
00267
00279 bool setPin(Pin pin, bool set);
00280
00292 bool getPin(Pin pin, bool &is_set);
00293
00304 SigC::Signal2<void, char*, int> charactersReceived;
00305
00306
00307 protected:
00308
00309 private:
00310 const std::string serial_port;
00311 bool canonical;
00312
00313 int fd;
00314 struct termios port_settings;
00315 SerialDevice *dev;
00316
00317
00318 };
00319
00320
00321 }
00322
00323 #endif
00324
00325
00326
00327
00328
00329
00330