2

I am about to start a new project that works with a USB HID device. I know to send a command to a HID device, you use the following method:

controlTransfer(int requestType, int request, int value, int index, byte[] buffer, int length, int timeout);

While I am pretty sure what requestType, buffer, length, and timeout are, I don't clearly understand request, value, and index. What do these arguments do and what would I pass to send the my commands?

For example, if I were to set speed on a treadmill that has a specified command to set speed, what would I pass? The documentation I got was not clear about this.

Pink Jazz
  • 784
  • 4
  • 13
  • 34

1 Answers1

2

Request, Value and Index can be found from USB specification. These are standard parameters for control pipe commands.

From USB spec 3.0 Section 9.3 -

enter image description here

Following is the table for the values corresponding to Request, Value and Index from USB spec -

enter image description here

Shaibal
  • 907
  • 8
  • 18
  • So, for example, I was given a list of commands for a treadmill that interfaces via USB HID (such as setting speed or incline), what would I use? – Pink Jazz Oct 03 '18 at 14:44
  • @PinkJazz the values will be class specific and you need to check the data sheet for that. For example, HID class specific request, GET_REPORT, bRequest = 0x1, wValue = 0x3, wIndex = Interface no. – Shaibal Oct 03 '18 at 16:41
  • You can check HID specification of all the HID commands and the respective values. For treadmill, there will be specific feature commands which you should find in the data sheet of the product I believe. – Shaibal Oct 03 '18 at 16:44
  • bRequest will always be the command value. bIndex will be either endpoint number or interface number generally, bValue will depend on the command type. – Shaibal Oct 03 '18 at 16:45