Author Topic: Reading several reports at a time.  (Read 9698 times)

puppdn

  • Member
  • ***
  • Posts: 19
Reading several reports at a time.
« on: May 16, 2017, 03:45:53 am »
hi Jan!
Host application perform Overlapped read USB HID Device.

Did I understand correctly:
1. Device have REPORT_SIZE = 5, Hid driver (or windows) add extra byte for Packed ID. Overall length of REPORT is 6.
3-rd papameter of ReadFile() is nNumberOfBytesToRead. If I specify nNumberOfBytesToRead to 6 - everything works fine.

And now I want read 3 report at a time (6*3=18) bytes.
Now I specify nNumberOfBytesToRead as 18 and perform Overlapped read. As soon as Host received first report  -WaitForSingleObject() returns "WAIT_OBJECT_0" and GetOverlappedResult return lpNumberOfBytesTransferred as 6. And Buffer-receiver contain only 6 bytes.

As you said here:
 
HIDfaq says:
Why does ReadFile hang my application when I request to read a report?
ReadFile returns when one of more reports of the expected size are available or on a timeout if implemented.

But how can i wait for receiveng several reports?
Perform:
received=0;
While (received<18){
ReadFile()
WaitForSingleObject()
GetOverlappedResult(...,&received,..);
}

« Last Edit: May 16, 2017, 03:49:36 am by puppdn »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Reading several reports at a time.
« Reply #1 on: May 16, 2017, 12:54:01 pm »
An application can't request ReadFile to wait for multiple reports.

You can, however, put the ReadFiles in a separate thread that accumulates the desired number of reports and then returns the report data to the main thread.

puppdn

  • Member
  • ***
  • Posts: 19
Re: Reading several reports at a time.
« Reply #2 on: May 18, 2017, 06:54:01 am »
Well, seems that it's only way out.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Reading several reports at a time.
« Reply #3 on: May 19, 2017, 01:59:17 pm »
Yes, it's the way the HID driver was written.