PORTS Forum

Ports and Interfaces => USB => Topic started by: puppdn on May 16, 2017, 03:45:53 am

Title: Reading several reports at a time.
Post by: puppdn 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 (http://janaxelson.com/hidfaq.htm) 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,..);
}

Title: Re: Reading several reports at a time.
Post by: Jan Axelson 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.
Title: Re: Reading several reports at a time.
Post by: puppdn on May 18, 2017, 06:54:01 am
Well, seems that it's only way out.
Title: Re: Reading several reports at a time.
Post by: Jan Axelson on May 19, 2017, 01:59:17 pm
Yes, it's the way the HID driver was written.