代码之家  ›  专栏  ›  技术社区  ›  lemming

没有这样的文件或目录c++boost库

  •  1
  • lemming  · 技术社区  · 7 年前

    我无法打开串行端口 以下是代码:

    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;
    }
    

    运行程序后,终端出现错误: failed, e=No such file or directory

    我通过cout在openport函数中检查变量路径是否正确

    当我把dmesg | 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
    

    有人知道怎么修吗?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Some programmer dude    7 年前

    在POSIX类型的系统(如Linux)上,所有标准设备都位于 /dev/ 目录您需要提供 满的 设备路径:

    openport("/dev/ttyUSB0");
    

    当你只通过时会发生什么 "ttyUSB0" 系统将在 现在的 目录