Will
Will

Reputation: 281

PyWinUSB Indecipherable Error Message

I'm trying to use PyWinUSB to communicate with a pretty simplistic USB device that I have. The device is two components; A wireless transceiver and the device itself, which has 5 buttons, a rotary dial and a dip switch. Upon hitting any of the buttons (depending on the settings of the dial and switches), a value is transmitted to the transceiver.

The device can also receive signals for various purposes.

Using PyWinUSB, I've had no problems with receiving input from the device. The problem I'm having comes from when I try to send something to the device. That causes an error that I haven't been able to decipher as of yet. Even making rudimentary changes to the simple_send.py example program makes it explode.

I think the problem that I'm having is that I don't know what the target usage parameter. I'm not 100% certain what this does, but I've had some luck with it when I've grabbed the reports from the device after I've found it, but beyond that, I haven't been able to figure out why it keeps having the error and what I can do to fix it.

You can find the error itself here, and my version of the simple_send.py example here. Any feedback is appreciated.

Traceback (most recent call last):
  File "C:\2.7.x\pywinusb-0.3.1 2.7\examples\simple_send.py", line 45, in <module>
    click_signal(target_usage, target_vendor_id)
  File "C:\2.7.x\pywinusb-0.3.1 2.7\examples\simple_send.py", line 32, in click_signal
    report.send()
  File "C:\Python27\lib\site-packages\pywinusb-0.3.1-py2.7.egg\pywinusb\hid\core.py", line 1446, in send
    self.__prepare_raw_data()
  File "C:\Python27\lib\site-packages\pywinusb-0.3.1-py2.7.egg\pywinusb\hid\core.py", line 1401, in __prepare_raw_data
    byref(self.__raw_data), self.__raw_report_size) )
  File "C:\Python27\lib\site-packages\pywinusb-0.3.1-py2.7.egg\pywinusb\hid\winapi.py", line 382, in __init__
    raise helpers.HIDError("hidP error: %s" % self.error_message_dict[error_code])
HIDError: hidP error: data index not found

Upvotes: 0

Views: 1069

Answers (1)

Rene
Rene

Reputation: 36

Latest release includes a script to explore device capabilities it is called show_hids.py, it is in the ./example folder (download the full source package).

Run it on the command line, capture the output to a file (> output.txt) in order to facilitate reviewing it, then look for output and feature caps sections. There you'll find all the usages listed up by your device report descriptor (input caps points to the ones you can receive).

Upvotes: 2

Related Questions