简体   繁体   English

没有这样的文件或目录C ++ Boost库

[英]No such file or directory c++ boost library

I have trouble with opening serial port Here is code: 我在打开串口时遇到问题,代码如下:

void openport(const string & path)
{
     boost::system::error_code error;
     boost::asio::io_service io;
     boost::asio::serial_port port(io);
     port.open(path, error);
     if(ec)
     {
          cout << "failed" << ", e=" << ec.message().c_str() << endl;
     }
}
int main()
{
openport("ttyUSB0");
return 0;
}

and I got error in terminal after running program : failed, e=No such file or directory 并且在运行程序后终端出现错误: failed, e=No such file or directory

I checked at function openport via cout that variable path is correct 我通过cout在openport函数中检查了变量路径是否正确

When I put dmesg | 当我把dmesg | grep ttyUSB I got : 我得到的grep ttyUSB:

[11018.593665] usb 1-1.5: FTDI USB Serial Device converter now attached to ttyUSB0
[15414.150404] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
[15423.084984] usb 1-1.5: FTDI USB Serial Device converter now attached to ttyUSB0

Anyone know how to fix it? 谁知道怎么修它?

On POSIX-type systems (like eg Linux) all standard devices live in the /dev/ directory. 在POSIX类型的系统(例如Linux)上,所有标准设备都位于/dev/目录中。 You need to provide the full path to the device: 您需要提供设备的完整路径:

openport("/dev/ttyUSB0");

What happens when you pass only "ttyUSB0" is that the system will look for that device in the current directory. 当您仅传递"ttyUSB0" ,会发生系统将在当前目录中查找该设备的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM