Skip to content

Commit 18eb907

Browse files
committed
Re-enabled all UNIX baud rates. Improved README.md documentation.
1 parent 4623419 commit 18eb907

File tree

7 files changed

+156
-141
lines changed

7 files changed

+156
-141
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ cmake-build-debug/
44
.vscode/
55

66
# Sphinx build dir
7-
docs/_build/
7+
docs/_build/
8+
9+
# Build artifacts
10+
a.out

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## [v2.1.0] - 2020-11-08
11+
12+
### Added
13+
- Support for custom baud rates.
14+
- Support for all standard UNIX baud rates.
15+
- Improved Doxygen documentation.
16+
- Improved README.md documentation.
17+
18+
### Removed
19+
- Dependencies from the README, they weren't that useful and were not accurate anyway.
20+
1021
## [v2.0.3] - 2020-10-13
1122

1223
### Added

README.md

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# CppLinuxSerial
22

3-
Serial port library written in C++
3+
Linux serial port library written in C++.
44

55
[![Build Status](https://travis-ci.org/gbmhunter/CppLinuxSerial.svg?branch=master)](https://travis-ci.org/gbmhunter/CppLinuxSerial)
66

77
## Description
88

99
Library for communicating with COM ports on a Linux system.
1010

11-
Uses fstream to the file I/O.
11+
* Simple API
12+
* Supports custom baud rates
13+
* cmake based build system
1214

1315
## Installation
1416

@@ -67,13 +69,14 @@ using namespace mn::CppLinuxSerial;
6769
int main() {
6870
// Create serial port object and open serial port
6971
SerialPort serialPort("/dev/ttyUSB0", BaudRate::B_57600);
72+
// Use SerialPort serialPort("/dev/ttyACM0", 13000); instead if you want to provide a custom baud rate
7073
serialPort.SetTimeout(-1); // Block when reading until any data is received
7174
serialPort.Open();
7275

7376
// Write some ASCII datae
7477
serialPort.Write("Hello");
7578

76-
// Read some data back
79+
// Read some data back (will block until at least 1 byte is received due to the SetTimeout(-1) call above)
7780
std::string readData;
7881
serialPort.Read(readData);
7982

@@ -88,42 +91,15 @@ If the above code was in a file called `main.cpp` and you had installed `CppLinu
8891
g++ main.cpp -lCppLinuxSerial
8992
```
9093

91-
For more examples, see the `.cpp` files in `test/unit/`.
92-
93-
## Dependencies
94-
95-
The following table lists all of the libraries dependencies.
96-
97-
<table>
98-
<thead>
99-
<tr>
100-
<td>Dependency</td>
101-
<td>Comments</td>
102-
</tr>
103-
</thead>
104-
<tbody>
105-
<tr>
106-
<td>C++14</td>
107-
<td>C++14 used for strongly typed enums, `std::chrono` and literals.</td>
108-
</tr>
109-
<tr>
110-
<td>stdio.h</td>
111-
<td>snprintf()</td>
112-
</tr>
113-
<tr>
114-
<td>stty</td>
115-
<td>Used in unit tests to verify the serial port is configured correctly.</td>
116-
</tr>
117-
</tbody>
118-
</table>
94+
For more examples, see the files in `test/`.
11995

12096
## Issues
12197

12298
See GitHub Issues.
12399

124100
## FAQ
125101

126-
1. My code stalls when calling functions like `SerialPort::Read()`. This is probably because the library is set up to do a blocking read, and not enough characters have been received to allow `SerialPort::Read()` to return. Use `SerialPort::SetNumCharsToWait()` to determine how many characters to wait for before returning (set to 0 for non-blocking mode).
102+
1. My code stalls when calling functions like `SerialPort::Read()`. This is probably because the library is set up to do a blocking read, and not enough characters have been received to allow `SerialPort::Read()` to return. Call `SerialPort::SetTimeout(0)` before the serial port is open to set a non-blocking mode.
127103

128104
## Changelog
129105

include/CppLinuxSerial/SerialPort.hpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,11 @@
2424
// User headers
2525
#include "Exception.hpp"
2626

27-
28-
typedef unsigned int speed_t;
29-
// typedef struct termios2 {
30-
// tcflag_t c_iflag; /* input mode flags */
31-
// tcflag_t c_oflag; /* output mode flags */
32-
// tcflag_t c_cflag; /* control mode flags */
33-
// tcflag_t c_lflag; /* local mode flags */
34-
// cc_t c_line; /* line discipline */
35-
// cc_t c_cc[NCCS]; /* control characters */
36-
// speed_t c_ispeed; /* input speed */
37-
// speed_t c_ospeed; /* output speed */
38-
// } termios2_t;
39-
4027
namespace mn {
4128
namespace CppLinuxSerial {
4229

30+
/// \brief Represents the baud rate "types" that can be used with the serial port. STANDARD represents all
31+
/// the standard baud rates as provided by UNIX, CUSTOM represents a baud rate defined by an arbitray integer.
4332
enum class BaudRateType {
4433
STANDARD,
4534
CUSTOM,
@@ -72,6 +61,7 @@ namespace mn {
7261
B_CUSTOM, // Placeholder
7362
};
7463

64+
/// \brief Represents the state of the serial port.
7565
enum class State {
7666
CLOSED,
7767
OPEN,
@@ -90,13 +80,14 @@ namespace mn {
9080
/// \brief Constructor that sets up serial port with the basic (required) parameters.
9181
SerialPort(const std::string &device, speed_t baudRate);
9282

93-
//! @brief Destructor. Closes serial port if still open.
83+
/// \brief Destructor. Closes serial port if still open.
9484
virtual ~SerialPort();
9585

9686
/// \brief Sets the device to use for serial port communications.
9787
/// \details Method can be called when serial port is in any state.
9888
void SetDevice(const std::string &device);
9989

90+
/// \brief Allows the user to set a standard baud rate.
10091
void SetBaudRate(BaudRate baudRate);
10192

10293
/// \brief Allows the user to set a custom baud rate.
@@ -139,15 +130,16 @@ namespace mn {
139130
/// \brief Returns a populated termios structure for the passed in file descriptor.
140131
// termios GetTermios();
141132

142-
143-
144133
/// \brief Configures the tty device as a serial port.
145134
/// \warning Device must be open (valid file descriptor) when this is called.
146135
void ConfigureTermios();
147136

148137
// void SetTermios(termios myTermios);
149138

139+
/// \brief Returns a populated termios2 structure for the serial port pointed to by the file descriptor.
150140
termios2 GetTermios2();
141+
142+
/// \brief Assigns the provided tty settings to the serial port pointed to by the file descriptor.
151143
void SetTermios2(termios2 tty);
152144

153145
/// \brief Keeps track of the serial port's state.

0 commit comments

Comments
 (0)