Category : serial-port

I’m trying to use Boost.Asio to read from and write to a serial port. Here is my code: void async_read(boost::asio::serial_port& serial_port) { auto buffer = std::make_shared<std::vector<uint8_t>>(64); serial_port.async_read_some(boost::asio::buffer(*buffer), [buffer, &serial_port](const boost::system::error_code& error, size_t bytes_read) { if (error) { std::cout << "Error reading serial port: " << error.message() << std::endl; return; } std::string message(buffer->begin(), buffer->end()); std::cout << ..

Read more

I am trying to set up serial port communication in a c++ application on Ubuntu 20. I am opening the serial port like this: serialPort = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY); if (serialPort == -1) { perror("FAILED "); exit(1); } fcntl(serialPort, F_SETOWN, getpid()); fcntl(serialPort, F_SETFL, (FNDELAY | FASYNC)); struct termios options; tcgetattr(serialPort, &options); cfsetispeed(&options, ..

Read more