Visual Servoing Platform  version 3.4.1 under development (2021-12-05)
vpSerial.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Serial communication.
33  *
34  * Authors:
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 
39 #ifndef _vpSerial_h_
40 #define _vpSerial_h_
41 
42 #if !defined(_WIN32)
43 
44 #include <string>
45 #include <stdint.h>
46 
47 #include <visp3/core/vpConfig.h>
48 
70 class VISP_EXPORT vpSerial
71 {
72 public:
76  typedef enum {
77  fivebits = 5,
78  sixbits = 6,
79  sevenbits = 7,
80  eightbits = 8
81  } bytesize_t;
82 
86  typedef enum {
87  parity_none = 0,
88  parity_odd = 1,
89  parity_even = 2
90  } parity_t;
91 
95  typedef enum {
96  stopbits_one = 1,
97  stopbits_two = 2,
98  } stopbits_t;
99 
103  typedef enum {
104  flowcontrol_none = 0,
106  flowcontrol_hardware
107  } flowcontrol_t;
108 
109  vpSerial(const std::string &port="", unsigned long baudrate = 9600,
110  bytesize_t bytesize = eightbits, parity_t parity = parity_none, stopbits_t stopbits = stopbits_one,
111  flowcontrol_t flowcontrol = flowcontrol_none);
112  virtual ~vpSerial();
113 
114  int available();
115  void close();
116 
121  unsigned long getBaudrate() {
122  return m_baudrate;
123  }
124 
130  return m_bytesize;
131  }
132 
137  flowcontrol_t getFlowcontrol() {
138  return m_flowcontrol;
139  }
140 
146  return m_parity;
147  }
148 
153  std::string getPort() {
154  return m_port;
155  }
156 
162  return m_stopbits;
163  }
164 
165  void open();
166  bool read(char *c, long timeout_s);
167  std::string readline(const std::string &eol);
168  void setBaudrate(const unsigned long baudrate);
169  void setBytesize(const bytesize_t &bytesize);
170  void setFlowcontrol(const flowcontrol_t &flowcontrol);
171  void setParity(const parity_t &parity);
172  void setPort(const std::string &port);
173  void setStopbits(const stopbits_t &stopbits);
174  void write(const std::string &s);
175 
176 private:
177  void configure();
178 
179  std::string m_port;
180  int m_fd;
181 
182  bool m_is_open;
183  bool m_xonxoff;
184  bool m_rtscts;
185 
186  unsigned long m_baudrate;
187 
188  parity_t m_parity;
189  bytesize_t m_bytesize;
190  stopbits_t m_stopbits;
191  flowcontrol_t m_flowcontrol;
192 
193 };
194 
195 #endif
196 #endif
flowcontrol_t
Definition: vpSerial.h:103
stopbits_t getStopbits()
Definition: vpSerial.h:161
std::string getPort()
Definition: vpSerial.h:153
stopbits_t
Definition: vpSerial.h:95
flowcontrol_t getFlowcontrol()
Definition: vpSerial.h:137
bytesize_t
Definition: vpSerial.h:76
unsigned long getBaudrate()
Definition: vpSerial.h:121
bytesize_t getBytesize()
Definition: vpSerial.h:129
parity_t getParity()
Definition: vpSerial.h:145
Software flow control.
Definition: vpSerial.h:105