Visual Servoing Platform  version 3.5.1 under development (2023-03-14)
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 <stdint.h>
45 #include <string>
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, bytesize_t bytesize = eightbits,
110  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() { return m_baudrate; }
122 
127  bytesize_t getBytesize() { return m_bytesize; }
128 
133  flowcontrol_t getFlowcontrol() { return m_flowcontrol; }
134 
139  parity_t getParity() { return m_parity; }
140 
145  std::string getPort() { return m_port; }
146 
151  stopbits_t getStopbits() { return m_stopbits; }
152 
153  void open();
154  bool read(char *c, long timeout_s);
155  std::string readline(const std::string &eol);
156  void setBaudrate(const unsigned long baudrate);
157  void setBytesize(const bytesize_t &bytesize);
158  void setFlowcontrol(const flowcontrol_t &flowcontrol);
159  void setParity(const parity_t &parity);
160  void setPort(const std::string &port);
161  void setStopbits(const stopbits_t &stopbits);
162  void write(const std::string &s);
163 
164 private:
165  void configure();
166 
167  std::string m_port;
168  int m_fd;
169 
170  bool m_is_open;
171  bool m_xonxoff;
172  bool m_rtscts;
173 
174  unsigned long m_baudrate;
175 
176  parity_t m_parity;
177  bytesize_t m_bytesize;
178  stopbits_t m_stopbits;
179  flowcontrol_t m_flowcontrol;
180 };
181 
182 #endif
183 #endif
stopbits_t getStopbits()
Definition: vpSerial.h:151
flowcontrol_t
Definition: vpSerial.h:103
@ flowcontrol_software
Software flow control.
Definition: vpSerial.h:105
bytesize_t getBytesize()
Definition: vpSerial.h:127
unsigned long getBaudrate()
Definition: vpSerial.h:121
stopbits_t
Definition: vpSerial.h:95
std::string getPort()
Definition: vpSerial.h:145
flowcontrol_t getFlowcontrol()
Definition: vpSerial.h:133
bytesize_t
Definition: vpSerial.h:76
parity_t getParity()
Definition: vpSerial.h:139