For Linux
CppLinuxSerial
一个简单好用的serial库 https://github.com/gbmhunter/CppLinuxSerial
- 下载、编译、安装如下
git clone https://github.com/gbmhunter/CppLinuxSerial.git
cd CppLinuxSerial/ && mkdir build && cd build
cmake ..
make
sudo make install
- 安装位置如下,生成了一个静态库,头文件也只有俩
Installing: /usr/local/lib/libCppLinuxSerial.a
-- Installing: /usr/local/include/CppLinuxSerial
-- Installing: /usr/local/include/CppLinuxSerial/SerialPort.hpp
-- Installing: /usr/local/include/CppLinuxSerial/Exception.hpp
- 测试
#include <CppLinuxSerial/SerialPort.hpp>
using namespace mn::CppLinuxSerial;
int main() {
SerialPort serialPort("/dev/ttyUSB0", BaudRate::B_57600);
serialPort.SetTimeout(-1);
serialPort.Open();
serialPort.Write("Hello");
std::string readData;
serialPort.Read(readData);
serialPort.Close();
}
|