将Linux/dev/USB作为标准文件访问以与USB设备通信 [英] Accessing Linux /dev/USB as standard files to communicate with USB device

查看:257
本文介绍了将Linux/dev/USB作为标准文件访问以与USB设备通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究与Linux中的USB设备通信的方法,并且希望不编写Linux内核驱动程序.我知道libusb存在并且是可以运行的用户级库,但是我们的嵌入式设备不支持usbfs(更改内核以添加支持确实很痛苦).

I'm researching ways to communicate with a USB device in Linux and would prefer to not write a Linux Kernel driver. I understand that libusb exists and is a user-land library that would work, but our embedded device doesn't support usbfs ( and would be really a pain to change kernels to add the support ).

所以我的问题基本上是这样的:是否可以/建议通过直接读写与USB设备相对应的/dev/USB或udev文件来与USB设备通信,从而绕过对自定义Linux驱动程序的需求和usbfs?

So my question is basically this: Is it possible / advisable to communicate with a USB device by directly reading and writing to the /dev/USB or the udev file corresponding to the USB device thus bypassing the need for a custom Linux Driver and usbfs?

我希望只要打开/dev/USB或udev设备文件,就可以直接通过文件类型的读/写命令直接读取/写入协议数据包,从而使用USB设备协议进行通信.

I'm hoping it's possible to communicate using the USB devices protocol just by reading / writing protocol packets directly through file-type read/write commands once the /dev/USB or udev device file is open.

请提出想法和建议.

跟进:

由于我需要与之交谈的USB设备是USB HID类设备,因此我可以通过直接读/写到/dev/hidraw0(或相应的/dev/)来使用libudev和标准Linux USB HID RAW驱动程序hidraw设备).不必为简单的USB HID设备编写自定义驱动程序.

Since the USB device I needed to talk to is a USB HID class device, I was able to use libudev and the standard Linux USB HID RAW driver by reading / writing directly to /dev/hidraw0 ( or the appropriate /dev/hidraw device ). It wasn't necessary to write a custom driver for a simple USB HID device.

推荐答案

吉姆,我认为您无法逃脱编写驱动程序的需要,而只是设法读取/dev中的USB文件.因为谁定义了在USB设备文件上执行read()时应该发生的事情?谁定义了调用sysioctl()时应启动的动作? 您的驱动程序!!换句话说,在基础驱动程序支持之前,设备文件本身无法执行任何操作.实际上,您可以将设备文件视为基础驱动程序的抽象!因此,没有驱动程序,没有使用设备文件:(

Jim, I don't think you can escape the need to write a driver and just manage to read the USB file in /dev. Because who defines as to what should happen when you do a read() on the USB device file? And who defines what action should be initiated when you invoke sysioctl()? Your driver! In other words, the device files are themselves incapable of anything until they are supported by the underlying drivers. In fact, you can treat the device files to be an abstraction of the underlying driver! So, no driver, no use of device file :(

我建议您阅读以下有关如何编写驱动程序并了解USB内部原理的文章-

I suggest you go through the following articles about how to write a driver and also understand the USB internals-

  1. http://www.linux-usb.org/USB -guide/c15.html

http://www.linuxjournal.com/article/4786 (略过期)

这篇关于将Linux/dev/USB作为标准文件访问以与USB设备通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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