Add CppLinuxSerial

This commit is contained in:
Alexander Popov 2024-01-27 23:52:22 +03:00
parent 6b535aa50b
commit 64c7319fce
Signed by: iiiypuk
GPG Key ID: E47FE0AB36CD5ED6
7 changed files with 76 additions and 0 deletions

3
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "rxi/log/3rdparty/log.c"]
path = rxi/log/3rdparty/log.c
url = https://github.com/rxi/log.c.git
[submodule "communication/cpp_linux_serial/3rdparty/CppLinuxSerial"]
path = communication/cpp_linux_serial/3rdparty/CppLinuxSerial
url = https://github.com/gbmhunter/CppLinuxSerial.git

24
LICENSE Normal file
View File

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>

View File

@ -0,0 +1,4 @@
# Примеры кода, алгоритмов и библиотек на Си (C++)
- [rxi/log](rxi/log) — ...
- [CppLinuxSerial](communication/cpp_linux_serial) — Библиотека для работы с Serial в связке с Arduino

View File

@ -0,0 +1,2 @@
serial_test
SerialPort.o

@ -0,0 +1 @@
Subproject commit 7401bd7b064fe0ed1e777364da651c28349c4086

View File

@ -0,0 +1,10 @@
PROGRAM = serial_test
CC = g++ -O2
HEADER = -I./3rdparty/CppLinuxSerial/include
all: $(PROGRAM)
$(PROGRAM):
cc $(HEADER) main.cpp SerialPort.o -o $@ -lstdc++
.PHONY: $(PROGRAM)

View File

@ -0,0 +1,32 @@
#include <chrono>
#include <thread>
#include <CppLinuxSerial/SerialPort.hpp>
using namespace mn::CppLinuxSerial;
#define PORT "/dev/ttyACM0"
#define WAIT_SEC 3
int main(int argc, char const *argv[]) {
SerialPort serialPort(PORT, BaudRate::B_9600, NumDataBits::EIGHT,
Parity::NONE, NumStopBits::ONE);
serialPort.SetTimeout(100);
std::cout << "Opening " PORT "... " << std::flush;
serialPort.Open();
std::cout << "OK" << std::endl;
std::cout << "Waiting Arduino restart... " << std::flush;
std::this_thread::sleep_for(std::chrono::seconds(WAIT_SEC));
std::cout << "OK" << std::endl;
std::cout << "Sending string data... " << std::flush;
std::string txDataString = "d";
serialPort.Write(txDataString);
std::cout << "OK" << std::endl;
std::cout << "Clossing port... " << std::flush;
serialPort.Close();
std::cout << "OK" << std::endl;
return 0;
}