我正在尝试创建一个将从串行端口读取和解析数据的类,但是我不断收到实例化错误,我不知道为什么。该类接受一个串行端口及其 io_service。我正在使用提升。我遇到了很多错误,但我认为这是因为它是累积的(我认为,我不确定这是否正确)。这是第一个:
在 /usr/include/boost/bind.hpp:22:0 包含的文件中,来自 ../Sources/Magnetic Compensator Core.cpp:17:
/usr/include/boost/bind/bind.hpp:在 'boost::_bi::result_traits&, const boost::system::error_code&, unsigned int)>' 的实例化中:/usr/include/boost/bind/bind_template .hpp:15:48: 从 'boost::_bi::bind_t&, const boost::system::error_code&, unsigned int), boost::_bi::list4, boost::reference_wrapper >, boost::arg< 1>, 升压::arg<2> > >'</p>
这是该类的代码:
class mag_serial
{
bool data_available;
boost::asio::serial_port& ser_port;
boost::asio::deadline_timer timeout;
char my_buffer[1];
std::string str;
std::string st;
void read_callback(bool& data_available, boost::asio::deadline_timer& timeout, const boost::system::error_code& error, std::size_t bytes_transferred)
{
data_available = true;
if(str.length() > 1)
{
if (!(str.at(str.length() - 1) == temp))//&str.at(str.length() - 1) != "#")
{
str.append(my_buffer,bytes_transferred);
if(str.at(str.length() - 1) == quit)
{
cout << "I am quitting";
Stop();
ser_port.cancel();
ser_port.close();
return;
}
i++;
}
else if (str.at(str.length() - 1) == temp)
{
st = str;//.substr(1, str.size());
// Processing Functions
}
}
else
{
str.append(my_buffer,bytes_transferred);
if(str.at(0) == quit)
{
cout << "I am quitting";
Stop();
ser_port.cancel();
ser_port.close();
return;
}
}
ser_port.async_read_some(boost::asio::buffer(my_buffer),
boost::bind(&mag_serial::read_callback, boost::ref(data_available),
boost::ref(timeout),boost::asio::placeholders::error(),
boost::asio::placeholders::bytes_transferred()));
data_available = true;
}
void wait_callback(boost::asio::serial_port& ser_port, const boost::system::error_code& error)
{
if (error)
{
// Data was read and this timeout was cancelled
return;
}
}
public:
mag_serial(boost::asio::serial_port& ser_port, boost::asio::io_service& io_svc): ser_port(ser_port), timeout(ser_port.get_io_service()){}
void read_mag_serial_thread()
{
bool data_available = false;
ser_port.async_read_some(boost::asio::buffer(my_buffer),
boost::bind(&mag_serial::read_callback, boost::ref(data_available),
boost::ref(timeout),boost::asio::placeholders::error(),
boost::asio::placeholders::bytes_transferred()));
timeout.expires_from_now(boost::posix_time::seconds(1));
timeout.async_wait(boost::bind(&mag_serial::wait_callback, boost::ref(ser_port),boost::asio::placeholders::error()));
io_svc.run();
if(!data_available)
{
ser_port.close();
cout << "ser_port was closed";
}
}
};