Skip to content

Commit a326528

Browse files
author
harunkurt.me
committed
add a file at cpp folder example1.cpp
1 parent d9ee37a commit a326528

File tree

7 files changed

+23
-0
lines changed

7 files changed

+23
-0
lines changed

cpp/a.out

74 KB
Binary file not shown.

cpp/example1.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <CppLinuxSerial/SerialPort.hpp>
2+
3+
using namespace mn::CppLinuxSerial;
4+
5+
int main() {
6+
// Create serial port object and open serial port at 57600 buad, 8 data bits, no parity bit, and one stop bit (8n1)
7+
SerialPort serialPort("/dev/ttyUSB0", BaudRate::B_57600, NumDataBits::EIGHT, Parity::NONE, NumStopBits::ONE);
8+
// Use SerialPort serialPort("/dev/ttyACM0", 13000); instead if you want to provide a custom baud rate
9+
serialPort.SetTimeout(-1); // Block when reading until any data is received
10+
serialPort.Open();
11+
12+
// Write some ASCII data
13+
serialPort.Write("Hello");
14+
15+
// Read some data back (will block until at least 1 byte is received due to the SetTimeout(-1) call above)
16+
std::string readData;
17+
serialPort.Read(readData);
18+
19+
std::cout<< readData<<std::endl;
20+
21+
// Close the serial port
22+
serialPort.Close();
23+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)