如何使用asio库打开USB端口并接收它的数据?
我有一个与另一个应用程序(不是我编写的)通信的设备,我想使用我的应用程序来获取它的价值。谷歌搜索我找到了ansio库,我安装了它并找到了这个教程入门。
问题:如何获取要在端口名称中设置的设备名称? 使用lsusb
,我得到:
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 004: ID 0ac8:305b Z-Star Microelectronics Corp. ZC0305 Webcam
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
我想处理网络摄像头设备:
Bus 001 Device 004: ID 0ac8:305b Z-Star Microelectronics Corp. ZC0305 Webcam
然后我写道:
try {
SimpleSerial serial("/dev/ttyUSB4",115200); // get SimpleSerial class on link above
cout<<serial.readLine()<<endl;
return 0;
} catch(boost::system::system_error& e)
{
cout<<"Error: "<<e.what()<<endl;
return 1;
}
但它给出了:错误:打开:没有这样的文件或目录
如何解决这个问题?提前致谢。
I have a device that communicates with another application(not written by me) that I want to get value of it using my application. googling I found the ansio library,I installed it and found this tutorial for getting started.
the question: how I to get the device name to set in port name?
using lsusb
, I get:
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 004: ID 0ac8:305b Z-Star Microelectronics Corp. ZC0305 Webcam
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
I want to handle the webcam device:
Bus 001 Device 004: ID 0ac8:305b Z-Star Microelectronics Corp. ZC0305 Webcam
then I wrote:
try {
SimpleSerial serial("/dev/ttyUSB4",115200); // get SimpleSerial class on link above
cout<<serial.readLine()<<endl;
return 0;
} catch(boost::system::system_error& e)
{
cout<<"Error: "<<e.what()<<endl;
return 1;
}
but it given an: Error: open: No such file or directory
how to fix this? thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 shell 中输入 ls /dev/tty* 并选择生成的端口之一。不幸的是,不能确定哪一个是正确的。否则,您可以尝试通过处理 dmesg 的输出来提取正确的端口。
Type
ls /dev/tty*
in the shell and choose one of the resulting ports. Unfortunately it can't be said for sure which one will be the right one. Otherwise you can try extracting the correct port by processing the output ofdmesg
.通常,当设备连接到 USB 端口时,它会在内核环形缓冲区中记录一条消息。此日志通常会为您提供所需的信息。要找到它,
dmesg
或dmesg | tail -20
查看缓冲区的最后 20 行。dmesg
命令的输出应类似于以下内容。注意:
Typically when a device is connected to a USB port, it is records a message in the kernel ring buffer. This log will often give you the information you are looking for. To find it,
dmesg
ordmesg | tail -20
to see the last 20 lines of the buffer.The output of the
dmesg
command should be something similar to the following.Notes: