00001 #ifndef SerialPort_H 00002 #define SerialPort_H 00003 00004 00005 #include <termios.h> 00006 #include <fcntl.h> 00007 00008 00009 #include <string> 00010 00011 00012 class SerialPort { 00013 public: 00014 SerialPort(const std::string &filename, const int speed, const mode_t mode = O_RDWR | O_NONBLOCK); 00015 ~SerialPort(); 00016 00017 operator int() const {return m_fd;} 00018 00019 bool fail() const {return (m_fd == -1);} 00020 00021 int setBaudRate(const int speed) const; 00022 int baudRate() const; 00023 00024 private: 00025 std::string m_filename; 00026 int m_fd; 00027 int m_speed; 00028 00029 static int rate(speed_t baud); 00030 static speed_t baud(const int speed); 00031 00032 // Not allowed to use these 00033 SerialPort(const SerialPort &port); 00034 SerialPort &operator=(const SerialPort &port); 00035 }; 00036 00037 00038 #endif