Author Topic: Trying to do something very simple - HID  (Read 9391 times)

DavidClarke

  • Member
  • ***
  • Posts: 24
Trying to do something very simple - HID
« on: April 22, 2019, 08:28:44 pm »
I am new to all of this.  Trying to teach myself. I will try to show only the most relevant code.

I know I have everything up to here working right:

hReadFile = CreateFile(FILE_NAME_ASCIIZ, %GENERIC_READ OR %GENERIC_WRITE, %FILE_SHARE_READ OR %FILE_SHARE_WRITE, BYVAL %NULL, %OPEN_EXISTING, %FILE_FLAG_OVERLAPPED, %NULL)

Because this works:
MY_OVERLAPPED.Offset     = 0
MY_OVERLAPPED.OffsetHigh = 0
MY_OVERLAPPED.hEvent = GLOBAL_EVENT_WAIT_FOR_OVERLAPPED_READ
RESULT = WaitForSingleObject(MY_OVERLAPPED.hEvent, 3000)     
RESULT = ReadFile(BYVL hReadFile ,  READ_BUFFER, MY_InputReportByteLength, BYTES_READ, MY_OVERLAPPED)

HOWEVER...
This does not work:
WRITE_BUFFER = "TEST"
MY_OVERLAPPED.Offset     = 0
MY_OVERLAPPED.OffsetHigh = 0
RESULT = WriteFile(GLOBAL_FILE_HANDLE, WRITE_BUFFER, MY_OutputReportByteLength, BYTES_WRITTEN, MY_OVERLAPPED)   

I keep getting error 87 - ERROR_INVALID_PARAMETER
If I have the WRITE_BUFFER mal-formed will WriteFile refuse to do the function?  I am watching the data on wireshark and cant get any data to from the host to the device.

I have lots of other stuff working - I can get all the info about the device etc...  Just can't write to it. 




Input Data Items
  ================


  ** Input "Value" ** (HID Report Main Item):
  ------------------------------------------
  (Contents of a Windows _HIDP_VALUE_CAPS data structure)
    .UsagePage: 0x9  USAGEPAGE_BUTTON
    .ReportID: 1
    .BitSize: 8
    .ReportCount: 1
    .LogicalMin: 0
    .LogicalMax: 255
    .PhysicalMin: 0
    .PhysicalMax: 0
    .UnitsExp: 0x0
    .Units: 0x0
    .LinkCollection: 0
    .LinkUsagePage: 0xC  USAGEPAGE_CONSUMER_DEVICES
    .LinkUsage: 0x1  CONSUME_CONSUMER_CONTROL
    Main Item bits:
      Data,
      Variable,
      Absolute,
      No Wrap,
      Linear,
      Has Preferred State,
      NO Null State,
      Non Volatile (Output and Feature items only),
      Bit Field,
    .IsAlias: False
    .IsRange: True
    .IsStringRange: False
    .IsDesignatorRange: False
    .IsAbsolute: True
    .HasNull: False
    .Range.UsageMin: 0x1  BUTTON_1
    .Range.UsageMax: 0xF  BUTTON_15
    .Range.StringMin: 0x0
    .Range.StringMax: 0x0
    .Range.DesignatorMin: 0x0
    .Range.DesignatorMax: 0x0
    .Range.DataIndexMin: 0x0
    .Range.DataIndexMax: 0xE
  Additional Information:
    (Array element 0)
    .Name: "BUTTON_1"
    .ReportType = Input
    .ReportID: 1
    .HasBeenAdded: False
    .UsagePage: 0x9  USAGEPAGE_BUTTON
    .UsageMin: 0x1  BUTTON_1
    .UsageMax: 0xF  BUTTON_15
    .SizeInBits: 8
    .MaxListLength: 15
    .ScaleMode = smBoth (Read both Unscaled and Scaled values)
  Scaled and Unscaled Values:
    Unscaled : .pValueList[0]^ = 0x0 = 0
      Scaled : .pScaledValueList[0]^ = 0x0 = 0
               .WriteAsScaled[0]: False
    Unscaled : .pValueList[1]^ = 0x0 = 0
      Scaled : .pScaledValueList[1]^ = 0x0 = 0
               .WriteAsScaled[1]: False
    Unscaled : .pValueList[2]^ = 0x0 = 0
      Scaled : .pScaledValueList[2]^ = 0x0 = 0
               .WriteAsScaled[2]: False
    Unscaled : .pValueList[3]^ = 0x0 = 0
      Scaled : .pScaledValueList[3]^ = 0x0 = 0
               .WriteAsScaled[3]: False
    Unscaled : .pValueList[4]^ = 0x0 = 0
      Scaled : .pScaledValueList[4]^ = 0x0 = 0
               .WriteAsScaled[4]: False
    Unscaled : .pValueList[5]^ = 0x0 = 0
      Scaled : .pScaledValueList[5]^ = 0x0 = 0
               .WriteAsScaled[5]: False
    Unscaled : .pValueList[6]^ = 0x0 = 0
      Scaled : .pScaledValueList[6]^ = 0x0 = 0
               .WriteAsScaled[6]: False
    Unscaled : .pValueList[7]^ = 0x0 = 0
      Scaled : .pScaledValueList[7]^ = 0x0 = 0
               .WriteAsScaled[7]: False
    Unscaled : .pValueList[8]^ = 0x0 = 0
      Scaled : .pScaledValueList[8]^ = 0x0 = 0
               .WriteAsScaled[8]: False
    Unscaled : .pValueList[9]^ = 0x0 = 0
      Scaled : .pScaledValueList[9]^ = 0x0 = 0
               .WriteAsScaled[9]: False
    Unscaled : .pValueList[10]^ = 0x0 = 0
      Scaled : .pScaledValueList[10]^ = 0x0 = 0
               .WriteAsScaled[10]: False
    Unscaled : .pValueList[11]^ = 0x0 = 0
      Scaled : .pScaledValueList[11]^ = 0x0 = 0
               .WriteAsScaled[11]: False
    Unscaled : .pValueList[12]^ = 0x0 = 0
      Scaled : .pScaledValueList[12]^ = 0x0 = 0
               .WriteAsScaled[12]: False
    Unscaled : .pValueList[13]^ = 0x0 = 0
      Scaled : .pScaledValueList[13]^ = 0x0 = 0
               .WriteAsScaled[13]: False
    Unscaled : .pValueList[14]^ = 0x0 = 0
      Scaled : .pScaledValueList[14]^ = 0x0 = 0
               .WriteAsScaled[14]: False
  Description string IDs:
    StringMin: 0
    StringMax: 0
    StringID[0] = 0
    String[0] = ""


  ** Input "Value" ** (HID Report Main Item):
  ------------------------------------------
  (Contents of a Windows _HIDP_VALUE_CAPS data structure)
    .UsagePage: 0x9  USAGEPAGE_BUTTON
    .ReportID: 1
    .BitSize: 8
    .ReportCount: 1
    .LogicalMin: 0
    .LogicalMax: 255
    .PhysicalMin: 0
    .PhysicalMax: 0
    .UnitsExp: 0x0
    .Units: 0x0
    .LinkCollection: 0
    .LinkUsagePage: 0xC  USAGEPAGE_CONSUMER_DEVICES
    .LinkUsage: 0x1  CONSUME_CONSUMER_CONTROL
    Main Item bits:
      Data,
      Variable,
      Absolute,
      No Wrap,
      Linear,
      Has Preferred State,
      NO Null State,
      Non Volatile (Output and Feature items only),
      Bit Field,
    .IsAlias: False
    .IsRange: False
    .IsStringRange: False
    .IsDesignatorRange: False
    .IsAbsolute: True
    .HasNull: False
    .NotRange.Usage: 0x1  BUTTON_1
    .NotRange.StringIndex: 0x0
    .NotRange.DesignatorIndex: 0x0
    .NotRange.DataIndex: 0xF
  Additional Information:
    (Array element 1)
    .Name: "BUTTON_1"
    .ReportType = Input
    .ReportID: 1
    .HasBeenAdded: False
    .UsagePage: 0x9  USAGEPAGE_BUTTON
    .UsageMin: 0x1  BUTTON_1
    .UsageMax: 0x1  BUTTON_1
    .SizeInBits: 8
    .MaxListLength: 1
    .ScaleMode = smBoth (Read both Unscaled and Scaled values)
  Scaled and Unscaled Values:
    Unscaled : .pValueList[0]^ = 0x0 = 0
      Scaled : .pScaledValueList[0]^ = 0x0 = 0
               .WriteAsScaled[0]: False
  Description string IDs:
    StringMin: 0
    StringMax: 0
    StringID[0] = 0
    String[0] = ""


=================


  ** Output "Value" ** (HID Report Main Item):
  -------------------------------------------
  (Contents of a Windows _HIDP_VALUE_CAPS data structure)
    .UsagePage: 0x9  USAGEPAGE_BUTTON
    .ReportID: 2
    .BitSize: 8
    .ReportCount: 1023
    .LogicalMin: 0
    .LogicalMax: 255
    .PhysicalMin: 0
    .PhysicalMax: 0
    .UnitsExp: 0x0
    .Units: 0x0
    .LinkCollection: 0
    .LinkUsagePage: 0xC  USAGEPAGE_CONSUMER_DEVICES
    .LinkUsage: 0x1  CONSUME_CONSUMER_CONTROL
    Main Item bits:
      Data,
      Variable,
      Absolute,
      No Wrap,
      Linear,
      Has Preferred State,
      NO Null State,
      Non Volatile (Output and Feature items only),
      Bit Field,
    .IsAlias: False
    .IsRange: False
    .IsStringRange: False
    .IsDesignatorRange: False
    .IsAbsolute: True
    .HasNull: False
    .NotRange.Usage: 0xFF00  BUTTON_65280
    .NotRange.StringIndex: 0x0
    .NotRange.DesignatorIndex: 0x0
    .NotRange.DataIndex: 0x0
  Additional Information:
    (Array element 0)
    .Name: "BUTTON_65280"
    .ReportType = Output
    .ReportID: 2
    .HasBeenAdded: False
    .UsagePage: 0x9  USAGEPAGE_BUTTON
    .UsageMin: 0xFF00  BUTTON_65280
    .UsageMax: 0xFF00  BUTTON_65280
    .SizeInBits: 8
    .MaxListLength: 1
    .ScaleMode = smBoth (Read both Unscaled and Scaled values)
  Scaled and Unscaled Values:
    Unscaled : .pValueList[0]^ = 0x0 = 0
      Scaled : .pScaledValueList[0]^ = 0x0 = 0
               .WriteAsScaled[0]: False
  Array of Values:
    .MaxArrayLength: 1023
    .CurrentArrayLength: 1023
    .MaxArrayBytes: 1023
      Raw bytes :
    .pValArray[0]^ = 0x0 = 0
    .pValArray[1]^ = 0x0 = 0
    .pValArray[2]^ = 0x0 = 0
    .pValArray[3]^ = 0x0 = 0
    .pValArray[4]^ = 0x0 = 0
    .pValArray[5]^ = 0x0 = 0
    .pValArray[6]^ = 0x0 = 0  etc....



 .pValArray[1017]^ = 0x0 = 0
    .pValArray[1018]^ = 0x0 = 0
    .pValArray[1019]^ = 0x0 = 0
    .pValArray[1020]^ = 0x0 = 0
    .pValArray[1021]^ = 0x0 = 0
    .pValArray[1022]^ = 0x0 = 0
  Description string IDs:
    StringMin: 0
    StringMax: 0
    StringID[0] = 0
    String[0] = ""

====================================================
End of Report: Output Report ID 2
====================================================


   

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Trying to do something very simple - HID
« Reply #1 on: April 23, 2019, 08:35:04 am »
The first byte in the write buffer should be the report ID.

The buffer should be large enough to hold the report + 1 byte.