Visual Servoing Platform  version 3.6.1 under development (2024-04-24)
vpSerial.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 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 _vpSerial_h_
35 #define _vpSerial_h_
36 
37 #if !defined(_WIN32)
38 
39 #include <stdint.h>
40 #include <string>
41 
42 #include <visp3/core/vpConfig.h>
43 
65 class VISP_EXPORT vpSerial
66 {
67 public:
71  typedef enum {
72  fivebits = 5,
73  sixbits = 6,
74  sevenbits = 7,
75  eightbits = 8
76  } bytesize_t;
77 
81  typedef enum {
82  parity_none = 0,
83  parity_odd = 1,
84  parity_even = 2
85  } parity_t;
86 
90  typedef enum {
91  stopbits_one = 1,
92  stopbits_two = 2,
93  } stopbits_t;
94 
98  typedef enum {
99  flowcontrol_none = 0,
101  flowcontrol_hardware
102  } flowcontrol_t;
103 
104  vpSerial(const std::string &port = "", unsigned long baudrate = 9600, bytesize_t bytesize = eightbits,
105  parity_t parity = parity_none, stopbits_t stopbits = stopbits_one,
106  flowcontrol_t flowcontrol = flowcontrol_none);
107  virtual ~vpSerial();
108 
109  int available();
110  void close();
111 
116  unsigned long getBaudrate() { return m_baudrate; }
117 
122  bytesize_t getBytesize() { return m_bytesize; }
123 
128  flowcontrol_t getFlowcontrol() { return m_flowcontrol; }
129 
134  parity_t getParity() { return m_parity; }
135 
140  std::string getPort() { return m_port; }
141 
146  stopbits_t getStopbits() { return m_stopbits; }
147 
148  void open();
149  bool read(char *c, long timeout_s);
150  std::string readline(const std::string &eol);
151  void setBaudrate(const unsigned long baudrate);
152  void setBytesize(const bytesize_t &bytesize);
153  void setFlowcontrol(const flowcontrol_t &flowcontrol);
154  void setParity(const parity_t &parity);
155  void setPort(const std::string &port);
156  void setStopbits(const stopbits_t &stopbits);
157  void write(const std::string &s);
158 
159 private:
160  void configure();
161 
162  std::string m_port;
163  int m_fd;
164 
165  bool m_is_open;
166  bool m_xonxoff;
167  bool m_rtscts;
168 
169  unsigned long m_baudrate;
170 
171  parity_t m_parity;
172  bytesize_t m_bytesize;
173  stopbits_t m_stopbits;
174  flowcontrol_t m_flowcontrol;
175 };
176 
177 #endif
178 #endif
stopbits_t getStopbits()
Definition: vpSerial.h:146
flowcontrol_t
Definition: vpSerial.h:98
@ flowcontrol_software
Software flow control.
Definition: vpSerial.h:100
bytesize_t getBytesize()
Definition: vpSerial.h:122
unsigned long getBaudrate()
Definition: vpSerial.h:116
stopbits_t
Definition: vpSerial.h:90
std::string getPort()
Definition: vpSerial.h:140
flowcontrol_t getFlowcontrol()
Definition: vpSerial.h:128
bytesize_t
Definition: vpSerial.h:71
parity_t getParity()
Definition: vpSerial.h:134