-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.cpp
More file actions
37 lines (32 loc) · 1.06 KB
/
tests.cpp
File metadata and controls
37 lines (32 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <serial_port.hpp>
int main()
{
try {
using namespace ports::literals;
ports::serial_port port{
"/dev/ttyUSB0"_p
.baud_rate(115'200)
.character_size(8)
.flow_control_none()
.parity_none()
.stop_bits_one()
};
std::cout << std::boolalpha;
std::string tx_message{"test"};
char rx_message[5]{};
while(true){
std::getchar();
std::cout << (port.send(tx_message, tx_message.length()) != port.error ?
"tx_message <" + tx_message + "> sent\n" :
"tx_message <" + tx_message + "> could not be sent!\n");
std::getchar();
std::cout << (port.receive_to(rx_message, tx_message.length()) != port.error ?
std::string{"rx_message <"} + rx_message + std::string{"> received\n"}:
"rx_message could not be received!\n");
}
} catch (const std::exception& e) {
std::cerr << e.what() << "\n";
}
return 0;
}