I'm trying to use a boost::shared_ptr
with async_read_until
and cannot get it to work. This is my simplified code:
header
boost::asio::io_service io_service;
typedef boost::shared_ptr<boost::asio::serial_port> serial_port_ptr;
serial_port_ptr serial_port;
boost::asio::streambuf response_data;
char delimiter = '\n';
boost::system::error_code error;
connect
serial_port = serial_port_ptr(new boost::asio::serial_port(io_service));
serial_port->open("/dev/ttyS0", error);
read
boost::asio::async_read_until(
serial_port.get(), response_data, delimiter,
boost::bind(
&serial_comm::data_received,
this, boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred
)
);
The error I get is no type named 'type' in 'struct std::enable_if<false, void>'
. Thank you.
You've provided a pointer as the input to boost::asio::async_read_until
instead of a reference. It should be rewritten like so:
boost::asio::async_read_until(
*serial_port, response_data, delimiter,
boost::bind(
&serial_comm::data_received,
this, boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred
)
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.