1
#define DELAY 1

func()
{
        auto readHandler = [&](const boost::system::error_code& ec, std::size_t bytesRead)->void
        {
            if(ec)
            {
                // Something went wrong
                std::cerr << ec.message() << "\n";
            }
        };
          string line;
          Sleep(DELAY);
          for(;;)
          {
            serial.async_read_some(boost::asio::buffer(&c, 1), readHandler);
            line += c;
          }
}

Why sleep is required before entering a loop. Without sleep, nothing is received by the buffer.

  • Its peculiar, but almost impossible to even speculate the reason when your code is not complete. I bet the problem is that you might block the write code part if not waiting, or something else so please write a [Minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) – Superlokkus Jul 23 '21 at 11:35

0 Answers0