4

Boost.Asio uses a Proactor to magnificently handle I/O using a single thread. I used it with sockets and I love it. I see that there is a way to use the io_service of Boost.Asio (and the underlying Proactor) with serial ports (COMX devices on Windows and /dev/ttyXXX on Linux) instead of sockets. In fact, I think that Boost.Asio is meant to be used with whatever type of I/O, including file handle and so on.

I am wondering if I can use it directly, out-of-the-box, for any serial devices like SPI or I2C. These kind of serial devices appear like /dev/spi under Linux.

For example, could I use it like this:

boost::asio::io_service my_io_service;
boost::asio::serial_port my_spi_serial_port("/dev/spi0", my_io_service);

and automagically, it works just like a regular serial port (i.e. RS232)?

Alternatively, if SPI is not directly supported by Boost.Asio, do the later offers a way of easily incorporate support for any other device type, without modifying the core code of Boost.Asio?

  • This can be made with extending(inheriting) io_service class or any descendant which fit your needs. – Galimov Albert Dec 20 '12 at 13:04
  • I started playing around with this, and to be strict, it is basic_service that needs to be extended and then registered to the io_service. However the documentation is very limited about the topic, I would greatly appreciate an example. – Philippe Cayouette Dec 22 '12 at 15:12
  • @PhilippeCayouette Though probably 9 years late: Did you have any success in doing this? – FloWil Feb 01 '22 at 14:25
  • @FloWil, I never got the chance to explore this option deeper unfortunately. – Philippe Cayouette Feb 02 '22 at 15:04

0 Answers0