Add CppLinuxSerial
This commit is contained in:
parent
6b535aa50b
commit
64c7319fce
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -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
24
LICENSE
Normal 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>
|
@ -0,0 +1,4 @@
|
||||
# Примеры кода, алгоритмов и библиотек на Си (C++)
|
||||
|
||||
- [rxi/log](rxi/log) — ...
|
||||
- [CppLinuxSerial](communication/cpp_linux_serial) — Библиотека для работы с Serial в связке с Arduino
|
2
communication/cpp_linux_serial/.gitignore
vendored
Normal file
2
communication/cpp_linux_serial/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
serial_test
|
||||
SerialPort.o
|
1
communication/cpp_linux_serial/3rdparty/CppLinuxSerial
vendored
Submodule
1
communication/cpp_linux_serial/3rdparty/CppLinuxSerial
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 7401bd7b064fe0ed1e777364da651c28349c4086
|
10
communication/cpp_linux_serial/Makefile
Normal file
10
communication/cpp_linux_serial/Makefile
Normal 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)
|
32
communication/cpp_linux_serial/main.cpp
Normal file
32
communication/cpp_linux_serial/main.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user