我是 python 新手,但有使用 HID 设备和 evdev 的经验。我有一个作为 HID 设备接口的二维条码扫描仪。目标是从二维码中获取字符串。我能够在 Linux 中识别扫描仪,甚至在 /dev/input 中找到它的位置。
我找到了 evdev 并用我的扫描仪实现了下面的示例。这只是他们网站上的默认代码。它读取值,但会打印带有起伏的长事件代码。我看不到将其转换为字符串的简单方法。我要做的就是从 Python 的 HID 扫描仪中读取一个字符串。任何帮助或指导将不胜感激(也许 evdev 不是答案)。
这是我当前的 python 代码和一些示例输出:
from evdev import *
dev = InputDevice('/dev/input/event1')
print(dev)
for event in dev.read_loop():
if event.type == ecodes.EV_KEY:
print(categorize(event))
以下是一些条形码的输出:
key event at 1383327570.147000, 2 (KEY_1), down
key event at 1383327570.147990, 2 (KEY_1), up
key event at 1383327570.148997, 3 (KEY_2), down
key event at 1383327570.150010, 3 (KEY_2), up
key event at 1383327570.151009, 29 (KEY_LEFTCTRL), down
key event at 1383327570.151009, 42 (KEY_LEFTSHIFT), down
key event at 1383327570.152017, 36 (KEY_J), down
key event at 1383327570.153005, 36 (KEY_J), up
key event at 1383327570.154004, 29 (KEY_LEFTCTRL), up
key event at 1383327570.155005, 32 (KEY_D), down
key event at 1383327570.155993, 32 (KEY_D), up
key event at 1383327570.157002, 48 (KEY_B), down
key event at 1383327570.158015, 48 (KEY_B), up
key event at 1383327570.158997, 48 (KEY_B), down
key event at 1383327570.282002, 18 (KEY_E), up
key event at 1383327570.283004, 49 (KEY_N), down
key event at 1383327570.284005, 49 (KEY_N), up
key event at 1383327570.284968, 18 (KEY_E), down
非常感谢!