Author Topic: Delayed HID Read  (Read 6466 times)

ProtonTim

  • Member
  • ***
  • Posts: 2
Delayed HID Read
« on: July 16, 2016, 12:54:18 pm »
Jan,

I am using a large portion of your generic_hid_cs_62 code to talk to a custom HID device.  When I send an OUT packet to the HID the HID responds by preparing data to be read by the next IN packet.  When I send the IN packet from the PC the HID responds immediately (it takes about 10mS for the HID to prepare the packet after receiving OUT packet) with the newly prepared packet.  However, what I read as a response from that IN packet at the PC is an older packet (I use sequence numbers to keep track of what data belongs to what packet).  I keep polling the HID and it keeps sending the correct packet, but the packet read by the PC software is an old packet, not the new one.  Finally, after about 300mS the right packet shows up in the software.  If I wait 300mS after the OUT packet to send the IN packet from the PC, I get the right packet back in the code.  Any faster than that and I am reading old packets until about 300mS has elapsed, even though the right packet has come across the USB bus numerous times and long before that (I am watching the traffic with a bus analyzer).

I am perplexed as to why this might be happening.  Any help would be greatly appreciated. I am grateful for the contribution you and your site have made to help me in my understanding of the USB protocol.

Warm Regards,
Tim

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Delayed HID Read
« Reply #1 on: July 16, 2016, 03:48:40 pm »
After sending new data, configure the IN endpoint to return NAK on all received IN token packets. When the endpoint has new data to send, configure the endpoint to send the data. Check your controller's data sheet for details on how to configure the endpoint.

(The host sends periodic IN token packets based on the bInterval value in the endpoint descriptor. It sounds like your endpoint is responding to all IN packets with whatever data is in the endpoint's buffer, and the PC's HID buffer is storing the received data.)

ProtonTim

  • Member
  • ***
  • Posts: 2
Re: Delayed HID Read
« Reply #2 on: July 16, 2016, 06:15:11 pm »
That is EXACTLY what was happening.  Thanks so much for your help.  You helped me have a happier weekend. :)

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Delayed HID Read
« Reply #3 on: July 16, 2016, 08:18:06 pm »
Glad you got it working!

Breshnev

  • Member
  • ***
  • Posts: 1
Re: Delayed HID Read
« Reply #4 on: August 09, 2016, 04:30:05 pm »
Good Afternoon Friend Jan Axelson
>
> I need you to help me with your program usbhidio.vbp Version: 2.1,
> this It works very well with my Digital Portable DYMOŽ USB Shipping
> Scale, but I have a small problem with the time that takes a long
> time in reading the data that it comes from the weight, it takes a
> long time 7 seconds, I would like you to tell me if some form exists
> of reading but quick the data that it comes from the scale, ahead of
> time thank you, my name is Breshnev Méndez and I am programmer visual
> basic 6.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Delayed HID Read
« Reply #5 on: August 09, 2016, 05:00:28 pm »
I will assume that you can't change the programming in the scale.

Assuming that the device sends data from the interrupt IN endpoint: the host's HID driver attempts to read data from a HID's IN endpoint at a frequency determined by the endpoint's bInterval value, typically 1 ms or 10 ms. The driver stores any received data in a buffer where applications can access it.

To get the data as quickly as possible, your application should initiate read operations as often as possible, for example, in a continuous loop.

A protocol analyzer could show whether the delay is in the device's sending the data or the application's retrieving it from the buffer.

If the vendor provides example code, that might help as well.