Hi boost users
I'm a newbie to boost trying to use a serial port as an iostream.
While searching the archives I found a post by Rob Desbois (2008-01-18
13:02) trying to achive the same. Unfortunately the solution wasn't
posted.
This is what I got so far:
#include
#include
class serial_device
{
public:
typedef char char_type;
typedef boost::iostreams::bidirectional_device_tag category;
serial_device(boost::asio::io_service& io_service, const std::string&
port, int baudrate = 9600) :
serial_port(io_service, port)
{
typedef boost::asio::serial_port_base spb;
serial_port.set_option(spb::baud_rate(baudrate));
};
std::streamsize read(char* buf, std::streamsize n)
{
boost::asio::read(serial_port, boost::asio::buffer(buf, n));
}
std::streamsize write(const char* buf, std::streamsize n)
{
boost::asio::write(serial_port, boost::asio::buffer(buf, n));
}
private:
boost::asio::serial_port serial_port;
};
int main(void)
{
boost::asio::io_service io_service;
serial_device serial(io_service, "/dev/ttyS0", 115200);
//boost::iostreams::stream s(serial);
}
If I uncomment the last line it fails to compile:
g++ -lboost_iostreams-mt -lboost_system-mt -lboost_thread-mt
iostream.cpp -o iostream
/usr/include/boost/noncopyable.hpp: In copy constructor
'boost::asio::basic_io_objectboost::asio::serial_port_service::basic_io_object(const
boost::asio::basic_io_objectboost::asio::serial_port_service&)':
/usr/include/boost/asio/basic_io_object.hpp:30: instantiated from
'boost::iostreams::stream::stream(Device&, int,
int) [with Device = serial_device, Tr = std::char_traits<char>, Alloc
= std::allocator<char>]'
iostream.cpp:36: instantiated from here
/usr/include/boost/noncopyable.hpp:27: error:
'boost::noncopyable_::noncopyable::noncopyable(const
boost::noncopyable_::noncopyable&)' is private
/usr/include/boost/asio/basic_io_object.hpp:30: error: within this context
/usr/include/boost/noncopyable.hpp: In copy constructor
'boost::asio::detail::reactive_descriptor_service
::implementation_type::implementation_type(const
boost::asio::detail::reactive_descriptor_serviceboost::asio::serial_port_service::basic_io_object(const
boost::asio::basic_io_objectboost::asio::serial_port_service&)':
/usr/include/boost/asio/basic_io_object.hpp:30: note: synthesized
method 'boost::asio::detail::reactive_descriptor_serviceboost::asio::serial_port_service::basic_serial_port(const
boost::asio::basic_serial_portboost::asio::serial_port_service&)':
/usr/include/boost/asio/basic_serial_port.hpp:51: note: synthesized
method 'boost::asio::basic_io_objectboost::asio::serial_port_service::basic_io_object(const
boost::asio::basic_io_objectboost::asio::serial_port_service&)'
first required here
iostream.cpp: In copy constructor 'serial_device::serial_device(const
serial_device&)':
iostream.cpp:5: note: synthesized method
'boost::asio::basic_serial_portboost::asio::serial_port_service::basic_serial_port(const
boost::asio::basic_serial_portboost::asio::serial_port_service&)'
first required here
/usr/include/boost/iostreams/stream.hpp: In constructor
'boost::iostreams::stream::stream(Device&, int,
int) [with Device = serial_device, Tr = std::char_traits<char>, Alloc
= std::allocator<char>]':
/usr/include/boost/iostreams/stream.hpp:129: note: synthesized method
'serial_device::serial_device(const serial_device&)' first required
here
make: *** [iostream] Error 1
Could anyone please explain what I'm doing wrong?
Thanks,
Chris
--
echo mailto: NOSPAM !#$.'<*>'|sed 's. ..'|tr "<*> !#:2" org@fr33z3