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