我正在尝试读取来自arduino的串行数据,但是当我运行程序时,它仅读取缓冲区中的所有数据,即程序启动之前实际发送的数据。然后我终止并出现以下错误:
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >'
what(): read: End of file
Aborted (core dumped)
Run Code Online (Sandbox Code Playgroud)
我什至不希望程序执行之前的数据。这是我的C ++代码:
#include <iostream>
#include <stdint.h>
#include <boost/asio.hpp>
#include <boost/asio/serial_port.hpp>
using namespace boost;
int main() {
asio::io_service io;
asio::serial_port port(io);
port.open("/dev/ttyUSB0");
port.set_option(asio::serial_port_base::baud_rate(115200));
char d;
while ( true ) {
asio::read(port, asio::buffer(&d, 1));
std::cout << d << std::endl;
}
port.close();
}
Run Code Online (Sandbox Code Playgroud)
据我所知,读取功能应该被阻塞,所以它等待下一个输入,对吗?那么如何到达“文件”的末尾?
所以我是lua的新手,我无法弄清楚你如何在数组中的数组中定位元素.
并且是一个与数组相同的表吗?为什么数组和对象具有相同的语法?有区别吗?