Skip to content

Commit b3b00e7

Browse files
author
harunkurt.me
committed
add CppLinıxSerial library and a make cpp/example1.cpp
1 parent a326528 commit b3b00e7

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

‎cpp/a.out‎

0 Bytes
Binary file not shown.

‎cpp/example1.cpp‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@ using namespace mn::CppLinuxSerial;
44

55
int main() {
66
// 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);
7+
SerialPort serialPort("/dev/ttyUSB0", BaudRate::B_9600, NumDataBits::EIGHT, Parity::NONE, NumStopBits::ONE);
88
// Use SerialPort serialPort("/dev/ttyACM0", 13000); instead if you want to provide a custom baud rate
99
serialPort.SetTimeout(-1); // Block when reading until any data is received
1010
serialPort.Open();
1111

1212
// Write some ASCII data
13-
serialPort.Write("Hello");
13+
// serialPort.Write("Hello");
1414

1515
// Read some data back (will block until at least 1 byte is received due to the SetTimeout(-1) call above)
1616
std::string readData;
17-
serialPort.Read(readData);
17+
while(true){
18+
serialPort.Read(readData);
1819

1920
std::cout<< readData<<std::endl;
21+
}
22+
2023

2124
// Close the serial port
2225
serialPort.Close();

0 commit comments

Comments
 (0)