Author Topic: Read data from device control endpoint.  (Read 18304 times)

sakit

  • Member
  • ***
  • Posts: 7
Read data from device control endpoint.
« on: April 12, 2016, 12:57:12 pm »
Hello every one. I need your help. I want to develop a simple application to write/read data to/from my HID device. http://i.stack.imgur.com/rQMtj.png and http://i.stack.imgur.com/9N3dP.png images represents all my HID device descriptors. I used all libraries which are mentioned http://janaxelson.com/hidpage.htm web site. But I can write to the device only. When I try to read my device response none of these libraries help me. The application is blocking and don't response even I press any button on my HID device. I think problem is all these libraries read device interrupt endpoint so that if device send the response to control endpoint these library can not read the coming data. http://janaxelson.com/files/SimpleHIDWrite3.zip this program only read my device data when I press any button. I can not find the source code of this software. I don't know what is the difference between this application used library and all other libraries. Can any one help me? Is there any other hid api library which can read both endpoints?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Read data from device control endpoint.
« Reply #1 on: April 12, 2016, 01:12:35 pm »
If your device is sending data from the control endpoint using an Input or Feature report, you will need application software that can request an Input or Feature report from the device. See my generic hid examples.

If the request fails, check the error message and use whatever debugging tools you have - protocol analyzer, monitor program, etc. - to try to isolate the problem.

The source code for SimpleHIDWrite3 is in HidTestSource.zip; the link is on my HID page.

sakit

  • Member
  • ***
  • Posts: 7
Re: Read data from device control endpoint.
« Reply #2 on: April 12, 2016, 01:34:27 pm »
My HID device has input and output report no any feature report. I check the HidTestSource. Is this source code is for SimpleHIDWrite software? because on your web site has also HidTest software I think this source code is belong to this software no SimpleHIDWrite. Are getReport() and read() functions the same? Because SimpleHIDWrite software has getReport() button and when I press this button I can read data. But the other hid apis has read() but this could not read

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Read data from device control endpoint.
« Reply #3 on: April 12, 2016, 08:17:33 pm »
I am not the author of the Delphi code and can't provide any help with it.

My example code on my HID page has the option to use interrupt or control transfers for input reports and includes source code.

sakit

  • Member
  • ***
  • Posts: 7
Re: Read data from device control endpoint.
« Reply #4 on: April 17, 2016, 09:04:50 pm »
I checked you example code. It help me a lot. How can I use this project as library to use cross platform.


sakit

  • Member
  • ***
  • Posts: 7
Re: Read data from device control endpoint.
« Reply #6 on: April 22, 2016, 02:58:43 am »
Thank you very much. I have one problem too. I wrote the library successfully. When I use this library on Windows 10 32 bit system I can read and write. But when I run on window 7 32 bit system i can write only. when i try to read always return 0 bytes. I check the code and found that on windows 7 32 bit sytem HidD_GetInputReport return false. How can I solve this problem? why library work on windows 10 and not windows 7.

UPDATE
When I run my program on windows 7(32 bit system) GetInputReport return error code 23. But when I run on windows 10(32 bit) system it works correctly without any problem
23: Data error (cyclic redundancy check) I don't know how is possible.
here is my code which i used to reading data from my device:
Code: [Select]
JNIEXPORT jbyteArray JNICALL Java_RatingTerminal_CtrlReadInputReport(JNIEnv *jEnv, jobject jObj)
{
byte *buffer;
printf("report length %d",Capabilities.InputReportByteLength);
if (DeviceHandle == INVALID_HANDLE_VALUE) {
printf("DeviceHandle is invalid handle value\n");
return jEnv->NewByteArray(0);
}
buffer = new byte[Capabilities.InputReportByteLength];

//Read a report from the device using a control transfer.

/*
HidD_GetInputReport
Returns:
True on success
Requires:
A device handle returned by CreateFile.
A buffer to hold the report.
The report length returned by HidP_GetCaps in Capabilities.InputReportByteLength.
*/

if (!HidD_GetInputReport(DeviceHandle, buffer, Capabilities.InputReportByteLength))
{
DWORD lastError = GetLastError();
    //You have to cache the value of the last error here, because the call to
    //operator<<(std::ostream&, const char *) may cause the last error to be set
    //to something else.
    std::cout << "Reading failure. GetLastError returned "
    << lastError << ".";
delete buffer;
return jEnv->NewByteArray(0);
}

jbyteArray inputReport = jEnv->NewByteArray(Capabilities.InputReportByteLength);
jEnv->SetByteArrayRegion(inputReport, 0, Capabilities.InputReportByteLength, (jbyte*)buffer);
delete buffer;
return inputReport;
}
« Last Edit: April 22, 2016, 03:45:53 am by sakit »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Read data from device control endpoint.
« Reply #7 on: April 22, 2016, 10:53:23 am »
Windows returns the CRC error code for a number of problems, not just CRC errors.

It's possible that the Windows 10 USB driver is more tolerant, or the Windows 7 system might have different timing that causes the device to fail to respond correctly.

A hardware protocol analyzer will show what is happening on the bus. If you don't have a hardware analyzer,  use a software analyzer and/or whatever other debugging tools you have to try to find out what is causing the error, for example, verify that the device received the request and sent the report.


sakit

  • Member
  • ***
  • Posts: 7
Re: Read data from device control endpoint.
« Reply #8 on: April 25, 2016, 01:15:11 am »
Thanks for your reply. I will try to what is happening. But what is the interesting for me when I use your program it works correctly. Is it possible that I missed some library file so that my library can not read on windows 7?
« Last Edit: April 25, 2016, 01:18:05 am by sakit »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Read data from device control endpoint.
« Reply #9 on: April 25, 2016, 05:49:02 pm »
Well that is a good clue, if you can examine what is different between my code and yours.

It looks like the application is attempting to read the Input report, but something (a parameter being passed?) isn't correct.

sakit

  • Member
  • ***
  • Posts: 7
Re: Read data from device control endpoint.
« Reply #10 on: April 28, 2016, 07:11:47 am »
I found that you program works correctly even on my computer not install wdk and ddk library. so it means that you put the necessary lib and header files to you project so that you program can run everywhere. I downloaded  http://janaxelson.com/files/usbhidio_vc6.zip your project and found one "readme.html" file and read. there you mentioned one link (http://www.lvr.com/usb.htm) which to help us to discover how we option those files. but unfortunately this link does not work. Can you help me to obtain these files and how to add all these to my project

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research

sakit

  • Member
  • ***
  • Posts: 7
Re: Read data from device control endpoint.
« Reply #12 on: May 01, 2016, 12:12:06 pm »
Thank you very much Ms. Jan. Finally I wrote the library both windows x86 and x64. (java library). The problem is related library which I used for Java project. So that it worked on windows 10 without problem. but only write function worked on windows 7. I used you sample code and develop new dll file for Java project and now works all windows platforms.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Read data from device control endpoint.
« Reply #13 on: May 01, 2016, 09:13:29 pm »
Excellent, thanks for reporting back!