简体   繁体   English

访问Linux / dev / USB作为标准文件以与USB设备通信

[英]Accessing Linux /dev/USB as standard files to communicate with USB device

I'm researching ways to communicate with a USB device in Linux and would prefer to not write a Linux Kernel driver. 我正在研究如何在Linux中与USB设备进行通信,而不愿意编写Linux内核驱动程序。 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 ). 我知道libusb存在并且是一个可以工作的用户区域库,但是我们的嵌入式设备不支持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或USB设备对应的udev文件,是否可以/建议与USB设备通信,从而绕过对自定义Linux驱动程序和usbfs的需求?

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. 我希望一旦/ dev / USB或udev设备文件打开,只需通过文件类型的读/写命令直接读/写协议包,就可以使用USB设备协议进行通信。

Thoughts and suggestions please. 请提出意见和建议。

FOLLOW UP: 跟进:

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 ). 由于我需要与之通信的USB设备是USB HID类设备,我可以通过直接读/写/ dev / hidraw0(或相应的/ dev / hidraw设备)来使用libudev和标准的Linux USB HID RAW驱动程序。 It wasn't necessary to write a custom driver for a simple USB HID device. 没有必要为简单的USB HID设备编写自定义驱动程序。

Jim, I don't think you can escape the need to write a driver and just manage to read the USB file in /dev . 吉姆,我认为你不能逃避编写驱动程序的需要,只是设法读取/dev的USB文件。 Because who defines as to what should happen when you do a read() on the USB device file? 因为谁定义了在USB设备文件上执行read()时应该发生什么? And who defines what action should be initiated when you invoke sysioctl() ? 谁定义了调用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 :( 所以,没有驱动程序,没有使用设备文件:(

I suggest you go through the following articles about how to write a driver and also understand the USB internals- 我建议你阅读以下有关如何编写驱动程序以及了解USB内部结构的文章 -

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

  2. http://www.linuxjournal.com/article/4786 ( Slightly outdated ) http://www.linuxjournal.com/article/4786 (略显过时)

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

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