Author Topic: HidD_SetOutputReport failing, error 31  (Read 16989 times)

rallysjd

  • Member
  • ***
  • Posts: 21
    • PiXCL Automation Technologies Inc
HidD_SetOutputReport failing, error 31
« on: March 31, 2012, 12:39:18 pm »
I have an STmicro HID demo app that sends reports to turn on LEDs. I understand the app code and the report f/w that works this.  I'm adding some Hid API command support into another app using HidD_SetOutputReport.

In the ST demo, the report is sent using WriteFile. In my app, HidD_SetOutputReport fails with error 31 (Device not working), and equivalent WriteFile fails with error 6 (Invalid handle).  In both cases, and in the ST app, CreateFile is called with the same device path. In my app I'm sending the same report bytes I send in the ST app. I can call other HID functions with the devide handle and get valid results.

HidD_SetOutputReport seems to be the correct HID API call to send a report to the board. In debug, just before the HidD_SetOutputReport I can run the ST app and the board responds correctly, turning on the LEDs, and yet I get these errors.

Suggestions?

SD

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: HidD_SetOutputReport failing, error 31
« Reply #1 on: March 31, 2012, 01:36:32 pm »
Be sure CreateFile requests write access.

Be sure the number of bytes you're sending corresponds to the number of bytes in a valid report + 1 byte for the report ID.

Jan

rallysjd

  • Member
  • ***
  • Posts: 21
    • PiXCL Automation Technologies Inc
Re: HidD_SetOutputReport failing, error 31
« Reply #2 on: March 31, 2012, 04:45:29 pm »
Thanks for the saturday reply. I've pretty much duplicated the code in the ST app in my code. WRITE access, and the report is 2 bytes: report # byte and state byte.  I can debug step the ST app and see what's being sent. It all looks the same as mine, but clearly there's a problem.

I'll double check...

SD

rallysjd

  • Member
  • ***
  • Posts: 21
    • PiXCL Automation Technologies Inc
Re: HidD_SetOutputReport failing, error 31
« Reply #3 on: April 01, 2012, 05:04:18 pm »
Well, I can now send the reports to the boards using WriteFile. HidD_SetOutputReport still fails, no idea why at present. Here's what I found.

The ST demo code was creating a Read and Write thread. CreateFile was called with the FILE_FLAG_OVERLAPPED attribute, so the ReadFile and WriteFile calls included an OVERLAPPED pointer. This makes sense, as the ST code allowed INPUTs and OUTPUTs.

I did not implement thread, just wanted to send some commands to the board. Threads will be needed later.

Code: [Select]
hHidDeviceObject = CreateFile((LPCTSTR)lpDevicePath,
                                        GENERIC_READ | GENERIC_WRITE,
                                        FILE_SHARE_READ FILE_SHARE_WRITE,
                                        NULL, //&SecurityAttributes,
                                        OPEN_EXISTING,
                                        0, NULL);


and later
Code: [Select]
returnValue = WriteFile(hHidDeviceObject,
                                            &ReportBuffer,2,
  &dwBytesWritten,
  NULL);

This (of course, now, in hindsight) makes sense. No OVERLAPPED I/O is needed in this case.

Still don't see why HidD_SetOutputReport fails.

SD
« Last Edit: April 01, 2012, 05:09:26 pm by rallysjd »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: HidD_SetOutputReport failing, error 31
« Reply #4 on: April 01, 2012, 08:56:43 pm »
What is your code for HidD_SetOutputReport?

Jan