need longer timeout with send_feature_report() for libusb under Linux #493

Open
opened 2023-01-03 03:01:21 -06:00 by elfmimi · 9 comments
elfmimi commented 2023-01-03 03:01:21 -06:00 (Migrated from github.com)

Some devices may require much longer timeout when submitting hid_send_feature_report() .

for such devices hid_send_feature_report() just notifies failure with return value of -1 .

I checked that internal error code libusb is reporting is LIBUSB_ERROR_TIMEOUT ( -7 ) .

Changing value here, from 1000 to, say, 5000 does make difference.
github.com/libusb/hidapi@c3a6150d88/libusb/hid.c (L1471)

You curious what the device is?
It is USB-HID control capable LCD monitor from EIZO . ex. FlexScan EV2670
Most requests to the monitor, for example a request to change speaker volume, work fine with short timeout .
But one specific request that is to enable or disable picture-by-picture mode only works with long timeout .

So it is better to have a measure to somehow specify custom value for timeout.

Some devices may require much longer timeout when submitting hid_send_feature_report() . for such devices hid_send_feature_report() just notifies failure with return value of -1 . I checked that internal error code libusb is reporting is LIBUSB_ERROR_TIMEOUT ( -7 ) . Changing value here, from 1000 to, say, 5000 does make difference. https://github.com/libusb/hidapi/blob/c3a6150d8801f79a59034045275176e9738b13e4/libusb/hid.c#L1471 You curious what the device is? It is USB-HID control capable LCD monitor from EIZO . ex. FlexScan EV2670 Most requests to the monitor, for example a request to change speaker volume, work fine with short timeout . But one specific request that is to enable or disable picture-by-picture mode only works with long timeout . **So it is better to have a measure to somehow specify custom value for timeout.**
Youw commented 2023-01-03 05:15:07 -06:00 (Migrated from github.com)

I guess it was only a matter of time when that magic number would backfire at us.
On the other hand it's been years and no one complained, until now.

But we definitely need a workaround for that. I think a libusb-specific option (e.g. int hid_libusb_set_output_timeout(hid_device *dev, unsigned int timeout) to be used with hid_write and hid_send_feature_report would suffice.

P.S.: PR is welcome.

I guess it was only a matter of time when that magic number would backfire at us. On the other hand it's been years and no one complained, until now. But we definitely need a workaround for that. I think a [libusb-specific](https://github.com/libusb/hidapi/blob/master/libusb/hidapi_libusb.h) option (e.g. `int hid_libusb_set_output_timeout(hid_device *dev, unsigned int timeout)` to be used with `hid_write` and `hid_send_feature_report` would suffice. P.S.: PR is welcome.
elfmimi commented 2023-01-03 08:47:39 -06:00 (Migrated from github.com)

Thank you for your quick response. I'm afraid I'm not sure if I want to do a PR myself for now.
It's like I spent way too much effort into finding this out , and so I felt like leaving a short note here.

Easiest workaround is to use libhidapi-hidraw instead of libhidapi-libusb .

Thank you for your quick response. I'm afraid I'm not sure if I want to do a PR myself for now. It's like I spent way too much effort into finding this out , and so I felt like leaving a short note here. Easiest workaround is to use libhidapi-hidraw instead of libhidapi-libusb .
Youw commented 2023-01-03 09:42:11 -06:00 (Migrated from github.com)

Easiest workaround is to use libhidapi-hidraw instead of libhidapi-libusb .

I'd say - a perfect one.

> Easiest workaround is to use libhidapi-hidraw instead of libhidapi-libusb . I'd say - a perfect one.
Youw commented 2023-01-03 09:50:34 -06:00 (Migrated from github.com)

For a historical reference:
HIDRAW has this timeout hard-coded as well: github.com/torvalds/linux@69b41ac87e/drivers/hid/usbhid/hid-core.c (L931)
And it is set to 5 seconds.

For a historical reference: HIDRAW has this timeout hard-coded as well: https://github.com/torvalds/linux/blob/69b41ac87e4a664de78a395ff97166f0b2943210/drivers/hid/usbhid/hid-core.c#L931 And it is set to [5](https://github.com/torvalds/linux/blob/69b41ac87e4a664de78a395ff97166f0b2943210/include/linux/usb.h#L1877) seconds.
mcuee commented 2023-01-19 02:24:55 -06:00 (Migrated from github.com)

I think we may want to promote the use of the hidraw backend for Linux and not the libusb backend.

I think we may want to promote the use of the hidraw backend for Linux and not the libusb backend.
Youw commented 2023-01-19 05:26:05 -06:00 (Migrated from github.com)

Totally agree. But that does not exclude having a potential fix for libusb backend.

Totally agree. But that does not exclude having a potential fix for libusb backend.
oistra-ah commented 2024-03-21 08:30:40 -05:00 (Migrated from github.com)

Hi,
could please someone give a hint: is it possible to increase timeout for send_feature_report() on Windows? I also have a device, which takes a more than 5 sec sometimes for response. Thanks.
@Youw

Hi, could please someone give a hint: is it possible to increase timeout for send_feature_report() on Windows? I also have a device, which takes a more than 5 sec sometimes for response. Thanks. @Youw
mcuee commented 2024-03-21 20:45:34 -05:00 (Migrated from github.com)

Hi, could please someone give a hint: is it possible to increase timeout for send_feature_report() on Windows? I also have a device, which takes a more than 5 sec sometimes for response. Thanks.

That is interesting, what is the device? The original issue only mentions Linux and only libusb backend.

> Hi, could please someone give a hint: is it possible to increase timeout for send_feature_report() on Windows? I also have a device, which takes a more than 5 sec sometimes for response. Thanks. That is interesting, what is the device? The original issue only mentions Linux and only libusb backend.
oistra-ah commented 2024-03-22 08:56:11 -05:00 (Migrated from github.com)

Hi, could please someone give a hint: is it possible to increase timeout for send_feature_report() on Windows? I also have a device, which takes a more than 5 sec sometimes for response. Thanks.

That is interesting, what is the device? The original issue only mentions Linux and only libusb backend.

Sorry for asking in this topic. I've just created #670. Device is a tiny USB climate sensor on the stm32f4

> > Hi, could please someone give a hint: is it possible to increase timeout for send_feature_report() on Windows? I also have a device, which takes a more than 5 sec sometimes for response. Thanks. > > That is interesting, what is the device? The original issue only mentions Linux and only libusb backend. Sorry for asking in this topic. I've just created #670. Device is a tiny USB climate sensor on the stm32f4
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-libusb/hidapi#493
No description provided.