SerialPort
A light-weight C++ library for cross-platform serial communication.
Loading...
Searching...
No Matches
src
interface.h
1
#ifndef SERIAL_PORT_INTERFACE_H
2
#define SERIAL_PORT_INTERFACE_H
3
4
#include <string>
5
6
#include "serial_port/types.h"
7
8
namespace
serial_port
9
{
10
12
class
Interface
13
{
14
// **************************************************************************
15
// **************************************************************************
16
17
public
:
18
// Constructors
19
Interface
() =
default
;
20
explicit
Interface
(
const
Settings
& settings);
21
Interface
(
const
std::string& port_name,
int
baud_rate,
22
Parity parity = Parity::kNone,
23
NumStopBits stop_bits = serial_port::NumStopBits::kOne,
24
bool
hardware_flow_control =
false
,
25
unsigned
long
int
timeout_s = 0,
unsigned
long
int
timeout_ms = 0);
26
// Allow moving a serial port
27
Interface
(
Interface
&&) =
default
;
28
Interface
& operator=(
Interface
&& other) =
default
;
29
// Do not allow copying a serial port
30
Interface
(
const
Interface
&) =
delete
;
31
Interface
& operator=(
const
Interface
& other) =
delete
;
32
33
// Destructor. Cannot call pure virtual methods in destructor so derived classes
34
// must call their respective Close() method in destructor themselves!
35
virtual
~Interface
() = 0;
36
37
38
virtual
void
Open() = 0;
39
virtual
void
Close() = 0;
40
virtual
bool
IsOpen() = 0;
41
[[nodiscard]]
const
Settings
& GetSettings()
const
;
42
43
virtual
unsigned
long
NumBytesAvailable() = 0;
44
virtual
void
FlushBuffer()
const
= 0;
45
46
virtual
unsigned
long
ReadData(
char
* data,
unsigned
long
num_bytes) = 0;
47
virtual
std::string ReadString();
48
49
virtual
unsigned
long
WriteData(
const
char
* data,
unsigned
long
num_bytes) = 0;
50
virtual
unsigned
long
WriteString(
const
std::string& str);
51
52
// **************************************************************************
53
// **************************************************************************
54
55
protected
:
56
Settings
settings_;
57
};
58
59
}
60
61
#endif
// !SERIAL_PORT_INTERFACE_H
serial_port::Interface
An abstract base class defining the interface of all serial port implementations.
Definition
interface.h:13
serial_port::Settings
Describes the settings of a port.
Definition
types.h:54
Generated by
1.12.0