28 static const unsigned int DefaultSerialTimeout = 100;
31 struct termios _termios;
34 int _timeout = Connection::DefaultSerialTimeout;
37 constexpr explicit Connection() : _termios(), _fd(-1) {}
54 std::vector<uint8_t>
send(std::vector<uint8_t> data);
58 [[nodiscard]] std::tuple<MB::ModbusResponse, std::vector<uint8_t>> awaitResponse();
59 [[nodiscard]] std::tuple<MB::ModbusRequest, std::vector<uint8_t>> awaitRequest();
61 [[nodiscard]] std::vector<uint8_t> awaitRawMessage();
63 void enableParity(
const bool parity) {
65 getTTY().c_cflag |= PARENB;
67 getTTY().c_cflag &= ~PARENB;
70 void setEvenParity() {
72 getTTY().c_cflag &= ~PARODD;
77 getTTY().c_cflag |= PARODD;
80 void setTwoStopBits(
const bool two) {
82 getTTY().c_cflag |= CSTOPB;
84 getTTY().c_cflag &= ~CSTOPB;
92 void setBaudRate(speed_t speed) {
114 throw std::runtime_error(
"Invalid baud rate");
116 cfsetospeed(&_termios, speed);
117 cfsetispeed(&_termios, speed);
121 termios &getTTY() {
return _termios; }
123 int getTimeout()
const {
return _timeout; }
125 void setTimeout(
int timeout) { _timeout = timeout; }