Skip to content

Commit

Permalink
Merge pull request #23 from gbmhunter/develop
Browse files Browse the repository at this point in the history
Release of v2.4.0.
  • Loading branch information
gbmhunter authored Feb 12, 2022
2 parents ad1770f + e1a7d93 commit 61f77cb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [v2.4.0] - 2022-02-12

- Added `Available()` method to return number of bytes ready to be read from the receive buffer (thanks lotricekCZ).
- Added CMake option for shared library (thanks lotricekCZ).

## [v2.3.0] - 2021-12-23

- Added support for setting the num. data bits.
Expand Down
8 changes: 5 additions & 3 deletions include/CppLinuxSerial/SerialPort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,12 @@ namespace mn {
/// \throws CppLinuxSerial::Exception if state != OPEN.
void ReadBinary(std::vector<uint8_t>& data);

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

/// \brief Returns a populated termios structure for the passed in file descriptor.
// termios GetTermios();
private:

/// \brief Configures the tty device as a serial port.
/// \warning Device must be open (valid file descriptor) when this is called.
Expand Down
11 changes: 10 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ file(GLOB_RECURSE CppLinuxSerial_SRC
file(GLOB_RECURSE CppLinuxSerial_HEADERS
"${CMAKE_SOURCE_DIR}/include/*.hpp")

add_library(CppLinuxSerial ${CppLinuxSerial_SRC} ${CppLinuxSerial_HEADERS})
option(SERIAL_BUILD_SHARED_LIBS "Build CppLinuxSerial shared library" OFF)

if (SERIAL_BUILD_SHARED_LIBS)
set(LibType SHARED)
else()
set(LibType STATIC)
endif()

add_library(CppLinuxSerial ${LibType} ${CppLinuxSerial_SRC} ${CppLinuxSerial_HEADERS})


target_include_directories(CppLinuxSerial PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>")
Expand Down
9 changes: 9 additions & 0 deletions src/SerialPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,15 @@ namespace CppLinuxSerial {
THROW_EXCEPT(std::string() + __PRETTY_FUNCTION__ + " called while state == OPEN.");
timeout_ms_ = timeout_ms;
}

int32_t SerialPort::Available() {
if(state_ != State::OPEN)
THROW_EXCEPT(std::string() + __PRETTY_FUNCTION__ + " called but state != OPEN. Please call Open() first.");
int32_t ret = 0;
ioctl(fileDesc_, FIONREAD, &ret);
return ret;

}

} // namespace CppLinuxSerial
} // namespace mn

0 comments on commit 61f77cb

Please sign in to comment.