Author Topic: Streaming data using a single report on a HID  (Read 14428 times)

tosa

  • Member
  • ***
  • Posts: 2
Streaming data using a single report on a HID
« on: May 13, 2011, 12:19:04 am »
Hi, I am able to send and receive single packet reports (<=64B) and large reports (which use multiple packets) just fine. What I'd like to do is use the 64B report to stream data to the host. I don't know how many bytes I need until run time, so any multiple of 64B is allowed. In my test case I'm sending two 64B reports to the host. I loop the filling of a 64B buffer in the HID (a SiLabs C8051F320) and send each report when full. I don't know how many reports are sitting on the ReadFile buffer at anytime (how do I find that out?). But I loop ReadFile and the second read timesout. I'm assuming it's because both reports are read at the same time? But my software buffer is only 64B, since I only expect 64B reports. Is that correct, or should it be size of the ReadFile buffer? But I don't think it should be the size of that buffer, since I tell it to read the 64B only. Please help me to understand if this is a good way to stream data and how to properly read streamed reports. Thanks!
« Last Edit: May 13, 2011, 12:28:20 am by tosa »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Streaming data using a single report on a HID
« Reply #1 on: May 13, 2011, 09:09:06 am »
The ReadFile buffer should be at least report size + 1 byte for the report ID.

ReadFile returns when at least one report is ready or on a timeout if defined.

If the HID driver's buffer has multiple reports ready, ReadFile will return as many reports as fit in the buffer.

So if the HID is sending reports at a high rater, you can reduce the number of calls to ReadFile by using a large buffer and retrieving multiple reports at once.

For example, if the buffer is 130 bytes, if the HID driver has two or more 64-byte reports ready, ReadFile will return the oldest two reports. If the HID driver has one report ready, ReadFile will return that report.

The only way to find out how many reports are ready is to try to read them.

Jan