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

查看:28
本文介绍了访问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 ).

所以我的问题基本上是这样的:是否可以/建议通过直接读写/dev/USB 或与 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/隐藏设备).没有必要为简单的 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.

推荐答案

Jim,我不认为你可以逃避编写驱动程序并设法读取 /dev.因为谁定义了在 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天全站免登陆