如何枚举USB设备并对其进行读/写操作? [英] How to enumerate USB devices *and* read/write to them?

查看:88
本文介绍了如何枚举USB设备并对其进行读/写操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个我需要与之通信的自定义USB设备.没有特定的驱动程序.该设备未显示为/dev/tty * .

There is a custom USB device I need to communicate with. There is no particular driver for it. The device doesn't show as /dev/tty*.

发现了如何使用 libudev 进行枚举USB设备,假设我设法获得了相应的 struct udev_device 结构.

I found out how I can use libudev to enumerate the USB devices and let's say I manage to get the corresponding struct udev_device.

我不知道如何对设备进行 open(2),这样我就可以 write(2) read(2).

What I can't figure out is how I can open(2) the device so I can write(2) to and read(2) from it.

是否可以与通用USB设备通信,设置波特率以及仅进行读/写?如果是这样,找到带有 libudev 的设备后应该打开哪个文件"?如果不是,是否需要编写内核级驱动程序?

Is it possible to communicate with a generic USB device, setting baudrate and just read/write? If so, what "file" should I open after I find the device with libudev? If not, is writing a kernel-level driver necessary?

推荐答案

libusb 是理想的选择.还有您所描述的这种情况的几个示例.

就您而言,您只需要:

  • 创建默认上下文.
  • 请求设备列表.
  • 搜索具有所需供应商/产品ID的设备.
  • 打开设备,然后通过同步异步 I/O调用.
  • 清理请求的设备列表.
  • 完成后,关闭设备句柄并破坏上下文.

这使您可以相对轻松地编写用户空间应用程序/库.我已经将它与麦克风,相机和DIY硬件(我构建的微型装配线设备)一起使用,并取得了相当大的成功.邮件列表中的开发人员也非常有帮助,尽管一个或两个研究员往往有点苛刻如果新成员的帖子写得不好,那就给他们.

This allows you to write a userspace application/library with relative ease. I've used it with microphones, cameras, and DIY hardware (mini assembly line devices I've built) with considerable success. The devs on the mailing list are also very helpful, though one or two fellows tend to be somewhat caustic to new members if their posts aren't perfectly written.

这篇关于如何枚举USB设备并对其进行读/写操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆