Vulcan Serial
Linux serial port library written in C++.
Library for communicating with COM ports on a Linux system.
- Simple API
- Supports custom baud rates
cmake
based build system.
#国内可能git可以使用代理ghproxy.com进行下载
#$ git clone https://ghproxy.com/https://github.com/Vulcan-YJX/VulcanSerial.git
$ git clone https://github.com/Vulcan-YJX/VulcanSerial.git
$ cd VulcanSerial
$ mkdir build && cd build
$ cmake ..
$ make
$ sudo make install
// fileName: main.cpp
#include "VulcanSerial/SerialPort.hpp"
#include <iostream>
using namespace VulcanSerial;
int main() {
SerialPort serialPort("/dev/ttyUSB0", BaudRate::B_115200, NumDataBits::EIGHT, Parity::NONE, NumStopBits::ONE);
serialPort.Open(); //set timeout 0, Open file as Non blocking, >0 as block
while(1){
while(serialPort.Available() > 0){
// Write some ASCII data
serialPort.Write("Vulcan Serial");
std::string readData;
serialPort.Read(readData);
std::cout << readData << std::endl;
}
}
// Close the serial port
serialPort.Close();
}
Make sure you have install VulcanSerial
lib.
g++ main.cpp -lVulcanSerial