在 linux 上读取 USB 输入流

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3737655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 23:11:43  来源:igfitidea点击:

Reading USB input stream on linux

linuxusbinputstreamdevice

提问by Dalton Conley

I'm working on an embedded linux machine and trying to read a USB devices input stream, but for some reason I don't have any such thing in my /dev directory. I would assume it would be something like /dev/ttyUSB01 or /dev/input/usb or something similar, but it's not there. dmesg returns the following

我正在嵌入式 linux 机器上工作并尝试读取 USB 设备输入流,但由于某种原因,我的 /dev 目录中没有任何此类内容。我认为它会像 /dev/ttyUSB01 或 /dev/input/usb 或类似的东西,但它不存在。dmesg 返回以下内容

[ 195.863911] input: GIT GIT USB READER as /class/input/input2
[ 195.864259] generic-usb 0003:1234:5678.0001: input: USB HID v1.00 Keyboard [GIT GIT USB READER] on usb-0000:00:0f.4-1/input0

I've scanned through /sys/class/input/input2 and I am not really sure what I'm looking for. Maybe someone could point me in the right direction?

我已经浏览了 /sys/class/input/input2 并且我不确定我在寻找什么。也许有人可以指出我正确的方向?

采纳答案by Karl Bielefeldt

Check out /dev/input/by-pathand look for your usb-0000:00:0f.4-1. On my Ubuntu box that's a symbolic link to the device.

检查/dev/input/by-path并寻找您的usb-0000:00:0f.4-1. 在我的 Ubuntu 盒子上,这是一个指向设备的符号链接。

回答by Bjorn

Have you tried using mdev? It's a lightweight alternative to udev and it populates /dev. If hotplugging is not enabled you might need to run it manually.

你试过使用 mdev 吗?它是 udev 的轻量级替代品,它填充 /dev。如果未启用热插拔,您可能需要手动运行它。

To scan /sys and create devices, try:

要扫描 /sys 并创建设备,请尝试:

mdev -s

回答by Lee Torres

Had the same problem a few days ago and we discovered this workaround.

几天前遇到了同样的问题,我们发现了这个解决方法。

You could do the following command at the terminal:

您可以在终端执行以下命令:

cat /proc/bus/input/devices

This will list your devices connected, and your devices should be on the list. For instance, one item on there appears this way for me:

这将列出您连接的设备,并且您的设备应该在列表中。例如,那里的一项对我来说是这样的:

I: Bus=0011 Vendor=0002 Product=000a Version=0000
N: Name="TPPS/2 IBM TrackPoint"
P: Phys=synaptics-pt/serio0/input0
S: Sysfs=/devices/platform/i8042/serio4/serio5/input/input15
U: Uniq=
H: Handlers=mouse1 event15 
B: PROP=0
B: EV=7
B: KEY=70000 0 0 0 0
B: REL=3

Under Handlers, you'll notice that event15 shows up. You can access the data stream by referencing /dev/input/event15 in my case. You'll have to figure out what it is in your case

在处理程序下,您会注意到 event15 出现了。在我的情况下,您可以通过引用 /dev/input/event15 来访问数据流。你必须弄清楚你的情况是什么