[boost.asio] reading data from serial port [newbie]

Hi Its my first cpp application with boost libs, therefore im asking for some help : The code is written In VS2008 and looks like this : include "stdafx.h" #include <iostream> #include <boost/asio.hpp> #include <boost/asio/serial_port.hpp> #include <boost/thread.hpp> #include <boost/system/error_code.hpp> #include <boost/system/system_error.hpp> #include <boost/bind.hpp> void handler( const boost::system::error_code& error)// Result of operation. //std::size_t bytes_transferred // Number of bytes read. { std::cout << "read" << std::endl; } int _tmain(int argc, _TCHAR* argv[]) { using namespace std; using namespace boost; char read_msg_[512]; /* All programs that use asio need to have at least one boost::asio::io_service object. */ /* This class provides access to I/O functionality. */ /* We declare an object of this type first thing in the main function. */ boost::asio::io_service io; asio::serial_port(io,"COM7"); boost::asio::serial_port::async_read_some(boost::asio::buffer(read_msg_,512) ,handler); return 0; } In line: boost::asio::serial_port::async_read_some(boost::asio::buffer(read_msg_,512) ,handler); Im getting compiler error : 1>c:\praca\visual\projekty\refernecje\refernecje\refernecje.cpp(32) : error C2352: 'boost::asio::basic_serial_port<>::async_read_some' : illegal call of non-static member function 1> c:\program files\boost\boost_1_36_0\boost\asio\basic_serial_port.hpp(595) : see declaration of 'boost::asio::basic_serial_port<>::async_read_some' Can You please explain me what is wrong ? the code is similar to that provided by boost serial port reading example. Thx in advance for help

boost::asio::io_service io; asio::serial_port(io,"COM7"); boost::asio::serial_port::async_read_some(boost::asio::buffer(read_msg_,512),handler);
return 0;
I never dealt with serial_port, but I guess you mean to define an object, like this: asio::serial_port thePort(io,"COM7"); ...and then to call its member-function: thePort.async_read_some(...);
participants (2)
-
Igor R
-
Wojciech L.Jędruch