3

I'm new to the Python hidapi although I've used the C version that it is based on before. The Python library is really different and I can't figure out how to use it from the one example that is provided. Does anyone know of any good documentation for this library?

If you're looking for a specific question, I'm trying to open an HID device that has multiple usages. My device has the following relevant characteristics:

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

I have tried using hid_enumerate to select the dictionary that I want but after instantiating the device object the device will not open even though I know it's there (since it is listed in enumerate).

ClydeTheGhost
  • 1,473
  • 2
  • 17
  • 31
  • Data communication is only **`single session`**(some users : "NOOO, how to write hdd with multisession ?", check `IC` level), create a communicator with minimum `delay` (delay setting `IC Clock/Prepare_data`). Create more thread for writing communicator class. – dsgdfg Jul 19 '16 at 06:22
  • I'm not sure what you're trying to get at. I don't want multiple sessions I just need to open with one of the usages but the hid.device.open() method picks the first usage and I want usage 8. – ClydeTheGhost Jul 19 '16 at 12:54

1 Answers1

7

Although I would still like to find some decent documentation, after using the C hidapi header for reference I found an answer to my original question. In order to specify the usage, you must use open_path() instead of the regular open() method (see below):

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
ClydeTheGhost
  • 1,473
  • 2
  • 17
  • 31