Skip to content

Windows&libusb: hid_write Issue: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress. (Regression from signal11 version, 1 sec write timeout issue!) #686

Open
@fricpa

Description

@fricpa

Hi. I have some USB HID devices here (with some old version of a proprietary firmware...) that work fine with signal11's hidapi (ca. 0.7.0/0.8.0), but create troubles with 0.14.0.

Interestingly, I only see the issues on Windows and on Linux with the -libusb backend - hidraw seems to work fine.
For the libusb backend I don't see the precise error (because #684).

The Windows backend says: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.

I think the culprit is the new rather strange (to me...) implementation of hid_write in Windows. Here's the diff of hid_write in my context
image
in my context, we build this into a JNI library for Java or call directly into into the hidapi .so with JNA and there is also usb4java (a libusb wrapper) involved, however I am quite convinced that these complications are not the culprit.

To give a bit more background, I see it failing like this:

2024-08-06T18:22:31,218 TRACE [main] org.hid4java.jna.HidApi - > [40]: 3f 3e 77 01 6d 6f 64 65 00 53 65 6e 73 6f 72 20 66 61 69 6c 65 64 00 53 68 75 74 64 6f 77 6e 00 4c 6f 77 20 62 61 74 74 65 72 79 3a 20 53 4c 45 45 50 00 52 65 63 68 61 72 67 65 20 73 6f 6f 6e
2024-08-06T18:22:31,220 TRACE [main] org.hid4java.jna.HidApi - > [40]: 3f 3e 00 41 74 74 72 69 62 75 74 69 6f 6e 00 66 61 69 6c 65 64 2c 00 73 74 61 72 74 20 61 67 61 69 6e 00 44 65 61 74 74 72 69 62 75 74 69 6f 6e 20 72 65 71 75 69 72 65 64 00 00 00 00 00 00 00
2024-08-06T18:22:31,221 TRACE [main] org.hid4java.jna.HidApi - > [40]: 3f 3e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
2024-08-06T18:22:32,237 ERROR [main] ***MainTest - inner error, devicePath=UsbDevicePath(vendorId=0x2047, productId=0x0301, serialNumber='703C936F1F000000'), lastKnownStatus=31119h,630636,0,0,0,0,0
 java.lang.RuntimeException: org.hid4java.jna.HidApiException: hid_write failed hid_error()='hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.'

our device is receiving a 512 byte block of data split into multiple 64 byte hid reports and apparently this firmware of the device performs some slow logic on that third message of all 0 there (since in this context, this message marks the end of the useful data of the block).

On a fairly low level of the USB stack then, probably, the device takes a long time to respond, maybe longer than 1000 ms (the device has a ti msp430 usb with the manufacturer's usb & hid stack if that helps as an info).

I don't understand why it was decided that 1000 was a good timeout to pick here or why overlapped io is used in the first place (even by the original implementation), given the api is intended to be synchronous.

I vote to revert to the signal11 implementation or remove overlapped io entirely, any reason not to? I will make my own branch replacing that code with signal11's version (or revert to 0.8.0) and keep testing, but at least for my context the old version reproducibly worked better while this version is BROKEN.

Metadata

Metadata

Assignees

No one assigned

    Labels

    WindowsRelated to Windows backendlibusbRelated to libusb backend

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions