README.md
CppLinuxSerial
Serial port library written in C++
Description
Library for communicating with COM ports on a Linux system.
Uses fstream to the file I/O.
Installation
Linux, MacOS, Windows
Make sure you have
cmakeinstalled.Clone the git repo onto your local storage.
Change into root repo directory:
$ cd CppLinuxSerialCreate a new build directory and change into it:
$ mkdir build $ cd buildRun cmake on the parent directory to generate makefile:
$ cmake ..Run make on the generated makefile to generate the static library
libCppLinuxSerial.aand an unit test executable:$ makeTo install the headers on your system:
$ sudo make installTo run the unit tests (NOTE: because this uses virtual serial ports via
stty, this only works on Linux!):$ make run_unit_testsIf you get errors such as
Could not open device /dev/ttyS10. Is the device name correct and do you have read/write permission?" thrown in the test fixture's constructor., it is probably an issue with either creating the virtual serial ports or permissions to access them.
Dependencies
The following table lists all of the libraries dependencies.
| Dependency | Comments |
| C++14 | C++14 used for strongly typed enums, `std::chrono` and literals. |
| stdio.h | snprintf() |
| stty | Used in unit tests to verify the serial port is configured correctly. |
Issues
See GitHub Issues.
FAQ
- 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 allowSerialPort::Read()to return. UseSerialPort::SetNumCharsToWait()to determine how many characters to wait for before returning (set to 0 for non-blocking mode).
Changelog
See CHANGELOG.md.