https://github.com/itas109/CSerialPort
CSerialPort - lightweight cross-platform serial port library and protocol parsing for C++/C/C#/Java/Python/Node.js/Electron/Rust
https://github.com/itas109/CSerialPort
android-serialport communication cpp cpp-serial cpp-serialport cross-platform cserialport linux linux-serialport mscomm protocol-parser rs232 serial serial-port serialport serialport-interface serialportassistant serialportsdk uart windows-serial
Last synced: 2 months ago
JSON representation
CSerialPort - lightweight cross-platform serial port library and protocol parsing for C++/C/C#/Java/Python/Node.js/Electron/Rust
- Host: GitHub
- URL: https://github.com/itas109/CSerialPort
- Owner: itas109
- License: other
- Created: 2016-05-07T03:16:19.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-11-13T15:25:05.000Z (3 months ago)
- Last Synced: 2025-11-13T17:22:53.749Z (3 months ago)
- Topics: android-serialport, communication, cpp, cpp-serial, cpp-serialport, cross-platform, cserialport, linux, linux-serialport, mscomm, protocol-parser, rs232, serial, serial-port, serialport, serialport-interface, serialportassistant, serialportsdk, uart, windows-serial
- Language: C++
- Homepage: https://blog.csdn.net/itas109/article/details/84282860
- Size: 10.1 MB
- Stars: 863
- Watchers: 37
- Forks: 360
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- fucking-awesome-cpp - CSerialPort - lightweight cross-platform serial port library. [LGPL3] (Serial Port)
- awesome-cpp - CSerialPort - lightweight cross-platform serial port library. [LGPL3] (Serial Port)
README
# [CSerialPort](https://github.com/itas109/CSerialPort)
[中文](README_zh_CN.md)
CSerialPort is a lightweight cross-platform serial port library based on C++, which can easy to read/write serial port and communication protocol parsing on multiple operating system. Also support C, C#, Java, Python, Node.js, Electron, Rust etc.
---
# Design Principles
- Cross-platform
- Easy to use
- Higher efficiency
- Custom protocol parsing
# Feature
- cross-platform windows linux macOS android freebsd
- sync and async read/write
- custom protocol parsing - [IProtocolParser](https://github.com/itas109/CSerialPort/tree/master/include/CSerialPort/IProtocolParser.h) and [CommNoGuiProtocol](https://github.com/itas109/CSerialPort/tree/master/examples/CommNoGuiProtocol)
- hot plug notify - [CSerialPortHotPlugListener](https://github.com/itas109/CSerialPort/tree/master/include/CSerialPort/SerialPortListener.h)
- third party language bindings - C, C#, Java, Python, Node.js, Electron, Rust - more information [bindings](https://github.com/itas109/CSerialPort/tree/master/bindings)
- usage tutorial - [CSerialPort Tutorial](https://blog.csdn.net/itas109/category_12416341.html)
- new cross-platform gui serial port tool - [CommMaster](https://gitee.com/itas109/CommMaster)
# Todo List
## Long-term Goal
- [ ] 1.support modern c++ standard
- [ ] 2.support character interval time and custom protocol parsing
- [ ] 3.support raw sync、raw async and extend async mode
- [ ] 4.support script engine
## Short-term Goal
- [x] 1.cross-platform OS identify class
- [x] 2.cross-platform thread class
- [x] 3.cross-platform lock class
- [x] 4.cross-platform higher efficiency timer class
- [ ] 5.cross-platform thread pool class
- [ ] 6.Performance test report(Throughput && delay && packet dropout rates)
# Latest version
## Version: 4.3.3.250923
by itas109 on 2025-09-23
# Quick Start
```
$ git clone --depth=1 https://github.com/itas109/CSerialPort.git
$ cd CSerialPort
$ mkdir bin && cd bin
$ cmake ..
$ cmake --build .
```
run demo ( for example serial port lookback test on linux)
```
CSerialPort/bin $ ./CSerialPortDemoNoGui
[INFO] CSerialPort - OS: Linux, ProductName: Ubuntu 22.04.2 LTS, Arch: x86_64, ProcessorNum: 4, Compiler: gcc(11.4.0), Bit: 64, C++: 201703L, Bindings: , Version: https://github.com/itas109/CSerialPort - v4.3.3.250923
Version: https://github.com/itas109/CSerialPort - v4.3.3.250923
AvailableFriendlyPorts:
1 - /dev/ttyCH341USB0 QinHeng CH340 serial converter 1a86:7523
2 - /dev/pts/0 0 pty terminal
Please Input The Index Of Port(1 - 2)
1
Port Name: /dev/ttyCH341USB0
[INFO] openPort - portName: /dev/ttyCH341USB0, baudRate: 9600, dataBit: 8, parity: 0, stopBit: 0, flowControl: 0, mode: async, readBufferSize:4096(4096), readIntervalTimeoutMS: 0, minByteReadNotify: 1, byteReadBufferFullNotify: 3276
[INFO] openPort - open /dev/ttyCH341USB0. code: 0, message: success
Open /dev/ttyCH341USB0 Success
Code: 0, Message: success
[INFO] writeData - write. len: 5, hex(top100): 3132333435
[INFO] writeData - write. len: 7, hex(top100): 69746173313039
[INFO] commThreadMonitor - write buffer(usedLen 12). len: 12, hex(top100): 313233343569746173313039
[INFO] commThreadMonitor - onReadEvent min read byte. portName: /dev/ttyCH341USB0, readLen: 12
[INFO] readData - read. len: 12, hex(top100): 313233343569746173313039
/dev/ttyCH341USB0 - Count: 1, Length: 12, Str: 12345itas109, Hex: 0x31 0x32 0x33 0x34 0x35 0x69 0x74 0x61 0x73 0x31 0x30 0x39
```
# Install CSerialPort Using Vcpkg
You can download and install CSerialPort using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager
```
$ git clone https://github.com/Microsoft/vcpkg.git
$ cd vcpkg
$ ./bootstrap-vcpkg.sh
$ ./vcpkg install cserialport
```
# Cross Compile
- arm on ubuntu 20.04
```
$ sudo apt-get install g++-arm-linux-gnueabi
$ cd CSerialPort
$ mkdir bin_arm && cd bin_arm
$ cmake .. -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain_arm.cmake
$ cmake --build .
```
- aarch64 on ubuntu 20.04
```
$ sudo apt-get install g++-aarch64-linux-gnu
$ cd CSerialPort
$ mkdir bin_aarch64 && cd bin_aarch64
$ cmake .. -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain_aarch64.cmake
$ cmake --build .
```
- mips64el on ubuntu 20.04
```
$ sudo apt-get install g++-mips64el-linux-gnuabi64
$ cd CSerialPort
$ mkdir bin_mips64el && cd bin_mips64el
$ cmake .. -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain_mips64el.cmake
$ cmake --build .
```
- riscv64 on ubuntu 20.04
```
$ sudo apt-get install g++-riscv64-linux-gnu
$ cd CSerialPort
$ mkdir bin_riscv64 && cd bin_riscv64
$ cmake .. -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain_riscv64.cmake
$ cmake --build .
```
# Screenshot
## Gui
Demo Path: CSerialPort/examples/CommQT

Demo Path: CSerialPort/examples/CommElectron

## Web
Demo Path: CSerialPort/examples/CommWeb

## No Gui
Demo Path: CSerialPort/examples/CommNoGui

# Documents
[API Document](doc/CSerialPort_doc_en.chm)
[Directory List Document](doc/directory_list.md)
[Error Guide Document](doc/error_guide.md)
[Frequently Asked Questions](doc/FAQ.md)
# Contacting
- Email : itas109@qq.com
- QQ Group : [129518033](http://shang.qq.com/wpa/qunwpa?idkey=2888fa15c4513e6bfb9347052f36e437d919b2377161862948b2a49576679fc6)
# Links
- [CSDN Blog](https://blog.csdn.net/itas109)
- [Github](https://github.com/itas109/CSerialPort)
- [Gitee](https://gitee.com/itas109/CSerialPort)
# CSerialPort-based Applications
## 1. [CommMaster](https://gitee.com/itas109/CommMaster)
- support windows/linux/macos/raspberrypi and so on
- support custom port name
- support custom baudrate
- support custom language
- support custom theme
https://gitee.com/itas109/CommMaster

# Donate
[CSDN Blog](https://blog.csdn.net/itas109)
---
# Other branches
Only for windows branch : https://github.com/itas109/CSerialPort/tree/CSerialPort_win_3.0.3
Thanks for [Remon Spekreijse's serial library](http://www.codeguru.com/cpp/i-n/network/serialcommunications/article.php/c2483/A-communication-class-for-serial-port.htm)
---
# License
CSerialPort v3.0.0.171216 - v4.3.1.240204 is licensed under the LGPLv3
CSerialPort v4.3.2.250203 - present is licensed under the [LGPLv3 with LGPL-3.0-linking-exception](LICENSE)