12 file_desc = open(device.c_str(), O_RDWR | O_NOCTTY);
16 struct termios options;
17 int code = tcgetattr(file_desc, &options);
21 options.c_cflag = CS8 | CLOCAL | CREAD;
22 options.c_iflag = IGNPAR;
25 options.c_cc[VMIN] = 0;
26 options.c_cc[VTIME] = timeout;
27 code = cfsetspeed(&options, baudrate);
31 code = tcsetattr(file_desc, TCSANOW, &options);
35 code = fcntl(file_desc, F_SETFL, 0);
37 throw USARTException(
"Fehler beim Aktivieren des blockierenden Modus'");
47 int code = close(file_desc);
56 int code = tcflush(file_desc, TCIFLUSH);
63 int code = tcflush(file_desc, TCOFLUSH);
70 int code = tcdrain(file_desc);
77 int code = write(file_desc, buffer + offset, len);
80 std::string(__FUNCTION__) +
" failed: " + std::string(__FILE__) +
"#" + std::to_string(__LINE__) +
81 ", " + strerror(code) +
" (code " + std::to_string(code) +
" / " + std::to_string(len) +
")");
86 int bytes_avail, code;
87 auto start = std::chrono::steady_clock::now();
88 auto end = std::chrono::steady_clock::now();
91 code = ioctl(file_desc, FIONREAD, &bytes_avail);
94 std::string(__FUNCTION__) +
" failed: " + std::string(__FILE__) +
"#" + std::to_string(__LINE__) +
95 ", " + strerror(code) +
" (code " + std::to_string(code) +
")");
97 end = std::chrono::steady_clock::now();
99 std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 100;
100 if (elapsed >= timeout)
102 std::string(__FUNCTION__) +
" failed: " + std::string(__FILE__) +
"#" + std::to_string(__LINE__) +
103 ", " + std::to_string(elapsed) +
" / " + std::to_string(timeout) +
" ds");
105 while (bytes_avail < len);
107 code = read(file_desc, buffer + offset, len);
110 std::string(__FUNCTION__) +
" failed: " + std::string(__FILE__) +
"#" + std::to_string(__LINE__) +
111 ", " + strerror(code) +
" (code " + std::to_string(code) +
" / " + std::to_string(len) +
")");
133 this->baudrate = baudrate;
138 this->timeout = timeout;