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 #include <string.h>
00062
00066 class SerialIO
00067 {
00068 public:
00069
00071 enum HandshakeFlags
00072 {
00073 HS_NONE,
00074 HS_HARDWARE,
00075 HS_XONXOFF
00076 };
00077
00079 enum ParityFlags
00080 {
00081 PA_NONE,
00082 PA_EVEN,
00083 PA_ODD,
00084
00085 PA_MARK,
00086 PA_SPACE
00087 };
00088
00090 enum StopBits
00091 {
00092 SB_ONE,
00093 SB_ONE_5,
00094 SB_TWO
00095 };
00096
00098 SerialIO();
00099
00101 virtual ~SerialIO();
00102
00107 void setDeviceName(const char *Name) { m_DeviceName = Name; }
00108
00113 void setBaudRate(int BaudRate) { m_BaudRate = BaudRate; }
00114
00120 void changeBaudRate(int BaudRate);
00121
00127 void setMultiplier(double Multiplier = 1) { m_Multiplier = Multiplier; };
00128
00132 void SetFormat(int ByteSize, ParityFlags Parity, int StopBits)
00133 { m_ByteSize = ByteSize; m_Parity = Parity; m_StopBits = StopBits; }
00134
00138 void setHandshake(HandshakeFlags Handshake) { m_Handshake = Handshake; }
00139
00145 void setBufferSize(int ReadBufSize, int WriteBufSize)
00146 { m_ReadBufSize = ReadBufSize; m_WriteBufSize = WriteBufSize; }
00147
00152 void setTimeout(double Timeout);
00153
00160 void setBytePeriod(double Period);
00161
00166 int openIO();
00167
00171 void closeIO();
00172
00180 int readBlocking(char *Buffer, int Length);
00181
00182
00189 int readNonBlocking(char *Buffer, int Length);
00190
00196 int writeIO(const char *Buffer, int Length);
00197
00201 int getSizeRXQueue();
00202
00203
00206 void purge()
00207 {
00208 ::tcflush(m_Device, TCIOFLUSH);
00209 }
00210
00213 void purgeRx() {
00214 tcflush(m_Device, TCIFLUSH);
00215 }
00216
00221 void purgeTx() {
00222 tcflush(m_Device, TCOFLUSH);
00223 }
00224
00229 void flushTx() {
00230 tcdrain(m_Device);
00231 }
00232
00233 protected:
00234 ::termios m_tio;
00235 std::string m_DeviceName;
00236 int m_Device;
00237 int m_BaudRate;
00238 double m_Multiplier;
00239 int m_ByteSize, m_StopBits;
00240 ParityFlags m_Parity;
00241 HandshakeFlags m_Handshake;
00242 int m_ReadBufSize, m_WriteBufSize;
00243 double m_Timeout;
00244 ::timeval m_BytePeriod;
00245 bool m_ShortBytePeriod;
00246 };
00247
00248
00249 #endif //
00250