使用 Python hidapi 打开具有多种用途的设备

Using Python hidapi to open device with multiple usages

我是 Python hidapi 的新手,尽管我以前使用过它基于的 C 版本。 Python 库非常不同,我无法从提供的一个示例中弄清楚如何使用它。有人知道这个库的任何好的文档吗?

如果您要查找特定问题,我正在尝试打开具有多种用途的 HID 设备。我的设备具有以下相关特征:

vendor_id: 10618
product_id: 4
usage: 8
usage_page: 1
interface_number: 1

我已经尝试使用 hid_enumerate 来 select 我想要的字典,但是在实例化设备对象之后,设备将无法打开,即使我知道它在那里(因为它在枚举中列出) .

虽然我仍然想找到一些像样的文档,但在使用 C hidapi header 作为参考后,我找到了我最初问题的答案。为了指定用法,您必须使用 open_path() 而不是常规的 open() 方法(见下文):

import hid

#Get the list of all devices matching this vendor_id/product_id
vendor_id = 10618
product_id = 4
device_list = hid.enumerate(vendor_id, product_id)

#Find the device with the particular usage you want
device_dict = (device in device_list if device['usage'] == '8').next()
device = hid.device()
device.open_path(device_dict['path']) #Open from path