SysIo  1.9.0
Embedded Library and tools
serial.hpp
1 
9 #ifndef _SYSIO_SERIAL_HPP_
10 #define _SYSIO_SERIAL_HPP_
11 
12 #include <sysio/serial.h>
13 #include <string>
14 
26 class Serial {
27 
28  public:
32  typedef enum {
33 
34  Data5 = SERIAL_DATABIT_5,
35  Data6 = SERIAL_DATABIT_6,
36  Data7 = SERIAL_DATABIT_7,
37  Data8 = SERIAL_DATABIT_8,
38  UnknownDataBits = SERIAL_DATABIT_UNKNOWN
39  } DataBits;
40 
44  typedef enum {
45 
46  OneStop = SERIAL_STOPBIT_ONE,
47  TwoStop = SERIAL_STOPBIT_TWO,
48  OneAndHalfStop = SERIAL_STOPBIT_ONEHALF,
49  UnknownStopBits = SERIAL_STOPBIT_UNKNOWN
50  } StopBits;
51 
55  typedef enum {
56 
57  NoParity = SERIAL_PARITY_NONE,
58  EvenParity = SERIAL_PARITY_EVEN,
59  OddParity = SERIAL_PARITY_ODD,
60  SpaceParity = SERIAL_PARITY_SPACE,
61  MarkParity = SERIAL_PARITY_MARK,
62  UnknownParity = SERIAL_PARITY_UNKNOWN
63  } Parity;
64 
68  typedef enum {
69 
73  UnknownFlowControl = SERIAL_FLOW_UNKNOWN
74  } FlowControl;
78  Serial (const char * portname, int baudrate);
82  ~Serial();
86  bool open();
90  int baudrate() const;
94  void setBaudrate (int baudrate);
98  const char * port() const;
102  void setPort (const char * portname);
106  void close();
110  int fileno() const;
114  void flush();
118  FlowControl flowControl() const;
122  bool setFlowControl (FlowControl newFlowControl);
126  const char * flowControlName() const;
130  bool setFlowControlName (const char * newFlowControl);
131 
132 #if !defined(__DOXYGEN__)
133  // Swig access functions (python interface)
134  inline int getFileno() const {
135  return fileno();
136  }
137  inline int getBaudrate() const {
138  return baudrate();
139  }
140  inline const char * getPort() const {
141  return port();
142  }
143  inline int getFlowControl() const {
144  return flowControl();
145  }
146  inline const char * getFlowControlName() const {
147  return flowControlName();
148  }
149 
150  private:
151  int fd;
152  xSerialIos ios;
153  std::string _portname;
154 #endif /* __DOXYGEN__ not defined */
155 };
161 /* ========================================================================== */
162 #endif /* _SYSIO_SERIAL_HPP_ */
const char * port() const
int fileno() const
bool setFlowControlName(const char *newFlowControl)
bool setFlowControl(FlowControl newFlowControl)
void flush()
void close()
DataBits
Definition: serial.hpp:32
FlowControl flowControl() const
int baudrate() const
void setPort(const char *portname)
const char * flowControlName() const
Parity
Definition: serial.hpp:55
Serial(const char *portname, int baudrate)
bool open()
void setBaudrate(int baudrate)
FlowControl
Definition: serial.hpp:68
StopBits
Definition: serial.hpp:44