Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
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
70class VISP_EXPORT vpSerial
71{
72public:
76 typedef enum
77 {
79 sixbits = 6,
82 } bytesize_t;
83
87 typedef enum
88 {
92 } parity_t;
93
97 typedef enum
98 {
101 } stopbits_t;
102
106 typedef enum
107 {
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
168private:
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};
185END_VISP_NAMESPACE
186#endif
187#endif
stopbits_t getStopbits()
Definition vpSerial.h:155
@ flowcontrol_software
Software flow control.
Definition vpSerial.h:109
@ flowcontrol_none
No flow control.
Definition vpSerial.h:108
@ flowcontrol_hardware
Hardware flow control.
Definition vpSerial.h:110
bytesize_t getBytesize()
Definition vpSerial.h:131
@ parity_odd
Check for odd parity.
Definition vpSerial.h:90
@ parity_none
No parity check.
Definition vpSerial.h:89
@ parity_even
Check for even parity.
Definition vpSerial.h:91
unsigned long getBaudrate()
Definition vpSerial.h:125
@ stopbits_two
2 stop bits are used
Definition vpSerial.h:100
@ stopbits_one
1 stop bit is used
Definition vpSerial.h:99
std::string getPort()
Definition vpSerial.h:149
vpSerial(const std::string &port="", unsigned long baudrate=9600, bytesize_t bytesize=eightbits, parity_t parity=parity_none, stopbits_t stopbits=stopbits_one, flowcontrol_t flowcontrol=flowcontrol_none)
Definition vpSerial.cpp:104
flowcontrol_t getFlowcontrol()
Definition vpSerial.h:137
@ eightbits
Data is encoded with 8 bits.
Definition vpSerial.h:81
@ fivebits
Data is encoded with 5 bits.
Definition vpSerial.h:78
@ sevenbits
Data is encoded with 7 bits.
Definition vpSerial.h:80
@ sixbits
Data is encoded with 6 bits.
Definition vpSerial.h:79
parity_t getParity()
Definition vpSerial.h:143