/VulcanSerial

linux Serial library

Primary LanguageC++MIT LicenseMIT

Vulcan Serial

License language platform

VulcanSerial

​ Linux serial port library written in C++.

Description 项目描述

Library for communicating with COM ports on a Linux system.

  • Simple API
  • Supports custom baud rates
  • cmake based build system.

Quick Start 快速开始

#国内可能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

Examples 测试案例

// 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