Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
SerialPort.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4
5#include "../File/File.h"
6
7namespace SC
8{
9
12
15
17struct SC_COMPILER_EXPORT SerialSettings
18{
19 enum class DataBits : uint8_t
20 {
21 Bits5 = 5,
22 Bits6 = 6,
23 Bits7 = 7,
24 Bits8 = 8,
25 };
26
27 enum class Parity : uint8_t
28 {
29 None = 0,
30 Odd,
31 Even,
32 };
33
34 enum class StopBits : uint8_t
35 {
36 One = 1,
37 Two = 2,
38 };
39
40 enum class FlowControl : uint8_t
41 {
42 None = 0,
43 Software,
44 Hardware,
45 };
46
47 uint32_t baudRate = 9600;
48 DataBits dataBits = DataBits::Bits8;
49 Parity parity = Parity::None;
50 StopBits stopBits = StopBits::One;
51 FlowControl flowControl = FlowControl::None;
52};
53
55struct SC_COMPILER_EXPORT SerialOpenOptions
56{
57 bool blocking = true;
58 bool inheritable = false;
59 bool exclusive = false;
60
61 SerialSettings settings;
62};
63
66struct SC_COMPILER_EXPORT SerialDescriptor : public FileDescriptor
67{
73
78
83};
84
86} // namespace SC
unsigned char uint8_t
Platform independent (1) byte unsigned int.
Definition PrimitiveTypes.h:36
unsigned int uint32_t
Platform independent (4) bytes unsigned int.
Definition PrimitiveTypes.h:38
[UniqueHandleDeclaration2Snippet]
Definition File.h:79
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition Result.h:13
Native serial port descriptor with configuration support.
Definition SerialPort.h:67
Result open(StringSpan path, const SerialOpenOptions &options=SerialOpenOptions())
Opens a serial port and applies the requested settings.
Result setSettings(const SerialSettings &settings)
Applies settings to an already opened serial descriptor.
Result getSettings(SerialSettings &settings) const
Reads current settings from an opened serial descriptor.
Open options for a serial descriptor.
Definition SerialPort.h:56
Serial port settings.
Definition SerialPort.h:18
An read-only view over a string (to avoid including Strings library when parsing is not needed).
Definition StringSpan.h:37