SERIAL++ library: simple serial port access
serialport.h
Go to the documentation of this file.
1 
38 // include guard
39 #ifndef TF_SERIALPORT_H_VERSION
40 
41 #include <fcntl.h>
42 #include <termios.h>
43 #include <unistd.h>
44 #include <string>
45 
46 #define TF_SERIALPORT_H_VERSION \
47  "TF_SERIALPORT_H V1.1"
48 #define TF_SERIALPORT_H_CVSID \
49  "$Id$"
50 
51 namespace serialport {
52 
55  class SerialPort {
56  public:
58  SerialPort(const std::string& devname,
59  const int& flags=(O_RDWR | O_NOCTTY | O_NDELAY));
61  ~SerialPort();
63  void write(const std::string& text) const;
65  std::string read(const std::string& delim="\n") const;
67  int read(char* buffer, const int& bufsize) const;
69  void debug(const bool& flag) { Mdebug=flag; }
70 
72  void sendxon() const;
74  void sendxoff() const;
75 
77  void flowxon();
79  void mode7E1() const;
81  void baud9600() const;
83  void makeraw() const;
85  void setdefaults() const;
87  void clocal() const;
88  private:
90  int Mfd;
92  bool Mdebug;
94  struct termios Mdevoptions;
96  bool Musexon;
97  }; // class SerialPort
98 
99 } // namespace serialport
100 
101 #endif // TF_SERIALPORT_H_VERSION (includeguard)
102 
103 /* ----- END OF serialport.h ----- */
void setdefaults() const
set default values from ttydefaults.h
Definition: setdefaults.cc:48
void clocal() const
set clocal
Definition: serialport.cc:123
void baud9600() const
select 9600 baud
Definition: serialport.cc:159
std::string read(const std::string &delim="\) const
read from port until delimiter
Definition: serialport.cc:83
bool Musexon
use xon/xoff flow control
Definition: serialport.h:96
Root namespace of library.
Definition: doxygen.txt:26
struct termios Mdevoptions
remember device status
Definition: serialport.h:94
void makeraw() const
issue cfmakeraw
Definition: serialport.cc:170
void write(const std::string &text) const
write string to port
Definition: serialport.cc:73
void mode7E1() const
set 7 data bits, even parity, 1 stop bit
Definition: serialport.cc:133
SerialPort(const std::string &devname, const int &flags=(O_RDWR|O_NOCTTY|O_NDELAY))
open port by name of device file
Definition: serialport.cc:50
void debug(const bool &flag)
set debug mode
Definition: serialport.h:69
void sendxoff() const
send xoff
Definition: serialport.cc:118
int Mfd
file descriptor to this port
Definition: serialport.h:90
~SerialPort()
close port
Definition: serialport.cc:63
bool Mdebug
debug flag
Definition: serialport.h:92
void flowxon()
set xon/xoff slow control
Definition: serialport.cc:147
void sendxon() const
send xon
Definition: serialport.cc:113