Author Topic: usbhidio vb6 version in C# is not working  (Read 16888 times)

srini

  • Member
  • ***
  • Posts: 4
usbhidio vb6 version in C# is not working
« on: May 05, 2011, 10:38:30 pm »
Hello,
    Thank you John for directing me to this Portal.

    I am pretty new to the USB development. I am trying to read (no writing to the device) the data from a device connected through USB. When I try VB6 version of the  USBHIDIO, it is working fine and returning the values for the API calls (Usage & USage Page) properly.
    When I tried usbhidio_V2.3.cs, my device is detected properly with VID & PID. Since I don't have anything to write to the device, I passed reportID for  inFeatureReportBuffer[0] to read the values in ExchangeFeatureReports() method. It is returning Byte Array when I select the Exchafeature reports Raadio button on the UI & click on the cmdOnce button on the UI.
          I know, these are HEX bytes, the first returned value is ReportID, when I convert the 2nd value, some of my device's values are correct, but most of them are not. I don't know, what the rest of the elements represent.

   Since, the VB6 version worked perfectly well, I am wondering if anyone has the same solution in .NET, some of the hid.dll's functions are missing in HIDDeclarations.cs when I compared it with Apideclarations.bas. I am not sure, if they are missing, OR they are not available in .NET API.
   I hope, I explained my problem correct, please feel free to post your questions, if it is not clear.

Thank you in advance
Srini

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: usbhidio vb6 version in C# is not working
« Reply #1 on: May 05, 2011, 11:22:47 pm »
The application can read Feature reports but the data isn't what you expected to receive?

What do you expect to receive and what do you actually receive?

Using the VB6 application, you can read Feature reports and get the expected data?

Jan

srini

  • Member
  • ***
  • Posts: 4
Re: usbhidio vb6 version in C# is not working
« Reply #2 on: May 06, 2011, 01:29:36 pm »
Thank you for the reply Jan.
Yes, the application can read the feature reports, but the data is not clear.  The Device is a Battery with USB comunication
  EX: I have % capacity value to be read with a ReportID 33 (UsagePage 85; usage 66), I get the 5 Bytes Received are 21,64,42,00,00. In this HEX(21) = 33 in Decimal, that is Report ID and Hex(64)=100, the capacity which is correct. I am not sure what the rest of the Bytes represent
       I have Temperature to read with ReportID 26 (UsagePage 86; usage 34), Received Bytes are 1A, 33, 01, 00,00. In this Hex(1A)=26, Hex(33)=51. This is not correct. I should get a HEX value of 134, if I combine the Byte 2 & 3, 01 & 33, it is near to the expected value. I am not sure, if I should do it, as the expected result is more than 2 digits.
       I have Battery Current with ReportID 87 (UsaagePage 84, usage 31), Received Bytes are 57, 26, 00, 00,00. Hex(57)=87, Hex(26)=38, but I should get a value as 7.
       I am not sure, if I am doing right by sending the parameters inFeatureReportBuffer[0]=ReportID, inFeatureReportBuffer[1]=usagePage & inFeatureReportBuffer[2]=Usage. Because, the received byte are same when I change the UsagePage & Usage for the same ReportID. I need to read values with different UsagePage & Usage within the same ReportID
     
   Yes Jan, you are correct, using the VB6 application, I can read the Feature report and the values are as expected.

Thank you
Srini

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: usbhidio vb6 version in C# is not working
« Reply #3 on: May 09, 2011, 08:46:01 am »
According to Microsoft's documentation, the passed buffer for HidD_GetFeaure specifies only the report ID, not usages.

Applications can use received report data directly or use the HID API to parse the report data:

http://msdn.microsoft.com/en-us/library/ff538910%28VS.85%29.aspx

Jan

srini

  • Member
  • ***
  • Posts: 4
Re: usbhidio vb6 version in C# is not working
« Reply #4 on: May 09, 2011, 10:20:22 am »
Hello Jan,
         Thank you for the MS documentation. Any idea, on how to interpret the Byte Values?

Thank you
Srini

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: usbhidio vb6 version in C# is not working
« Reply #5 on: May 09, 2011, 01:38:33 pm »
The report descriptor describes the report's contents. Or use the HID API to extract individual elements.

Jan

srini

  • Member
  • ***
  • Posts: 4
Re: usbhidio vb6 version in C# is not working
« Reply #6 on: May 24, 2011, 12:49:07 pm »
Thank you Jan. I was able to retrieve all the necessary values.