Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #ifndef _SerialIO_H
00055 #define _SerialIO_H
00056
00057 #include <termios.h>
00058 #include <sys/select.h>
00059
00060 #include <string>
00061
00065 class SerialIO
00066 {
00067 public:
00068
00070 enum HandshakeFlags
00071 {
00072 HS_NONE,
00073 HS_HARDWARE,
00074 HS_XONXOFF
00075 };
00076
00078 enum ParityFlags
00079 {
00080 PA_NONE,
00081 PA_EVEN,
00082 PA_ODD,
00083
00084 PA_MARK,
00085 PA_SPACE
00086 };
00087
00089 enum StopBits
00090 {
00091 SB_ONE,
00092 SB_ONE_5,
00093 SB_TWO
00094 };
00095
00097 SerialIO();
00098
00100 virtual ~SerialIO();
00101
00106 void setDeviceName(const char *Name) { m_DeviceName = Name; }
00107
00112 void setBaudRate(int BaudRate) { m_BaudRate = BaudRate; }
00113
00119 void changeBaudRate(int BaudRate);
00120
00126 void setMultiplier(double Multiplier = 1) { m_Multiplier = Multiplier; };
00127
00131 void SetFormat(int ByteSize, ParityFlags Parity, int StopBits)
00132 { m_ByteSize = ByteSize; m_Parity = Parity; m_StopBits = StopBits; }
00133
00137 void setHandshake(HandshakeFlags Handshake) { m_Handshake = Handshake; }
00138
00144 void setBufferSize(int ReadBufSize, int WriteBufSize)
00145 { m_ReadBufSize = ReadBufSize; m_WriteBufSize = WriteBufSize; }
00146
00151 void setTimeout(double Timeout);
00152
00159 void setBytePeriod(double Period);
00160
00165 int openIO();
00166
00170 void closeIO();
00171
00179 int readBlocking(char *Buffer, int Length);
00180
00181
00188 int readNonBlocking(char *Buffer, int Length);
00189
00195 int writeIO(const char *Buffer, int Length);
00196
00200 int getSizeRXQueue();
00201
00202
00205 void purge()
00206 {
00207 ::tcflush(m_Device, TCIOFLUSH);
00208 }
00209
00212 void purgeRx() {
00213 tcflush(m_Device, TCIFLUSH);
00214 }
00215
00220 void purgeTx() {
00221 tcflush(m_Device, TCOFLUSH);
00222 }
00223
00228 void flushTx() {
00229 tcdrain(m_Device);
00230 }
00231
00232 protected:
00233 ::termios m_tio;
00234 std::string m_DeviceName;
00235 int m_Device;
00236 int m_BaudRate;
00237 double m_Multiplier;
00238 int m_ByteSize, m_StopBits;
00239 ParityFlags m_Parity;
00240 HandshakeFlags m_Handshake;
00241 int m_ReadBufSize, m_WriteBufSize;
00242 double m_Timeout;
00243 ::timeval m_BytePeriod;
00244 bool m_ShortBytePeriod;
00245 };
00246
00247
00248 #endif //
00249