CSerialPort
V4.3.1
中文
CSerialPort是一个基于C++的轻量级跨平台串口库,可以方便地在多种操作系统上读写串口。还支持 C、C#、Java、Python、Node.js、Electron 等。
CSerialPort在以下平台上进行了测试
由 itas109 发表于 2024-02-04
$ git clone --depth=1 https://github.com/itas109/CSerialPort.git
$ cd CSerialPort
$ mkdir bin && cd bin
$ cmake ..
$ cmake --build .
运行demo(例如linux上的串口回溯测试)
CSerialPort/bin $ ./CSerialPortDemoNoGui
Version: https://github.com/itas109/CSerialPort - V4.3.1.240204
AvailableFriendlyPorts:
1 - /dev/ttyUSB0 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/ttyUSB0
[CSERIALPORT_DEBUG] openPort - portName: /dev/ttyUSB0, baudRate: 9600, dataBit: 8, parity: 0, stopBit: 0, flowControl: 0, mode: async, readBufferSize:4096(4096), readIntervalTimeoutMS: 0, minByteReadNotify: 1
[CSERIALPORT_DEBUG] openPort - open /dev/ttyUSB0. code: 0, message: success
Open /dev/ttyUSB0 Success
Code: 0, Message: success
[CSERIALPORT_DEBUG] writeData - write. len: 5, hex(top100): 3132333435
[CSERIALPORT_DEBUG] writeData - write. len: 7, hex(top100): 69746173313039
[CSERIALPORT_DEBUG] commThreadMonitor - write buffer(usedLen 12). len: 12, hex(top100): 313233343569746173313039
[CSERIALPORT_DEBUG] commThreadMonitor - onReadEvent. portName: /dev/ttyUSB0, readLen: 12
[CSERIALPORT_DEBUG] readData - read. len: 12, hex(top100): 313233343569746173313039
/dev/ttyUSB0 - Count: 1, Length: 12, Str: 12345itas109, Hex: 0x31 0x32 0x33 0x34 0x35 0x69 0x74 0x61 0x73 0x31 0x30 0x39
您可以使用 vcpkg 依赖项管理器下载并安装 CSerialPort
$ git clone https://github.com/Microsoft/vcpkg.git
$ cd vcpkg
$ ./bootstrap-vcpkg.sh
$ ./vcpkg install cserialport
$ 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 .
$ 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 .
$ 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 .
$ 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 .
演示路径:CSerialPort/examples/CommQT
演示路径:CSerialPort/examples/CommTui
演示路径:CSerialPort/examples/CommNoGui
API文档目录列表 文档错误指南 文档常见问题
https://gitee.com/itas109/CommMaster
CommLite是tui基于CSerialPort的串口工具
https://github.com/itas109/CommLite
CSDN博客
仅适用于 Windows 分支:https://github.com/itas109/CSerialPort/tree/CSerialPort_win_3.0.3
感谢 Remon Spekreijse 的串行库
自 V3.0.0.171216 起使用 GNU Lesser General Public License v3.0