使用Python hidapi实现设备的多用途开放

2024-05-28 12:50:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我对pythonhidapi还是个新手,尽管我以前使用过它基于的C版本。Python库确实不同,我无法从提供的一个示例中找出如何使用它。有人知道这个图书馆有什么好的文档吗?在

如果你想问一个特定的问题,我试着打开一个有多种用途的HID设备。我的设备具有以下相关特性:

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

我尝试过使用hid_neumerate来选择我想要的字典,但是在实例化设备对象之后,即使我知道它在那里,设备也不会打开(因为它在enumerate中列出)。在


Tags: 文档版本id示例图书馆pageusage特性
1条回答
网友
1楼 · 发布于 2024-05-28 12:50:04

虽然我仍然想找到一些像样的文档,但是在使用C hidapi头作为参考之后,我找到了我最初问题的答案。为了指定用法,必须使用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

相关问题 更多 >

    热门问题