Skip to content

Commit 61f77cb

Browse files
authored
Merge pull request #23 from gbmhunter/develop
Release of v2.4.0.
2 parents ad1770f + e1a7d93 commit 61f77cb

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [v2.4.0] - 2022-02-12
9+
10+
- Added `Available()` method to return number of bytes ready to be read from the receive buffer (thanks lotricekCZ).
11+
- Added CMake option for shared library (thanks lotricekCZ).
12+
813
## [v2.3.0] - 2021-12-23
914

1015
- Added support for setting the num. data bits.

include/CppLinuxSerial/SerialPort.hpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,12 @@ namespace mn {
168168
/// \throws CppLinuxSerial::Exception if state != OPEN.
169169
void ReadBinary(std::vector<uint8_t>& data);
170170

171-
private:
171+
/// \brief Use to get number of bytes available in receive buffer.
172+
/// \returns The number of bytes available in the receive buffer (ready to be read).
173+
/// \throws CppLinuxSerial::Exception if state != OPEN.
174+
int32_t Available();
172175

173-
/// \brief Returns a populated termios structure for the passed in file descriptor.
174-
// termios GetTermios();
176+
private:
175177

176178
/// \brief Configures the tty device as a serial port.
177179
/// \warning Device must be open (valid file descriptor) when this is called.

src/CMakeLists.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ file(GLOB_RECURSE CppLinuxSerial_SRC
66
file(GLOB_RECURSE CppLinuxSerial_HEADERS
77
"${CMAKE_SOURCE_DIR}/include/*.hpp")
88

9-
add_library(CppLinuxSerial ${CppLinuxSerial_SRC} ${CppLinuxSerial_HEADERS})
9+
option(SERIAL_BUILD_SHARED_LIBS "Build CppLinuxSerial shared library" OFF)
10+
11+
if (SERIAL_BUILD_SHARED_LIBS)
12+
set(LibType SHARED)
13+
else()
14+
set(LibType STATIC)
15+
endif()
16+
17+
add_library(CppLinuxSerial ${LibType} ${CppLinuxSerial_SRC} ${CppLinuxSerial_HEADERS})
18+
1019

1120
target_include_directories(CppLinuxSerial PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>"
1221
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>")

src/SerialPort.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,15 @@ namespace CppLinuxSerial {
629629
THROW_EXCEPT(std::string() + __PRETTY_FUNCTION__ + " called while state == OPEN.");
630630
timeout_ms_ = timeout_ms;
631631
}
632+
633+
int32_t SerialPort::Available() {
634+
if(state_ != State::OPEN)
635+
THROW_EXCEPT(std::string() + __PRETTY_FUNCTION__ + " called but state != OPEN. Please call Open() first.");
636+
int32_t ret = 0;
637+
ioctl(fileDesc_, FIONREAD, &ret);
638+
return ret;
639+
640+
}
632641

633642
} // namespace CppLinuxSerial
634643
} // namespace mn

0 commit comments

Comments
 (0)