Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hid_read not returning expected data (libusb) #556

Closed
VexedUXR opened this issue May 17, 2023 · 4 comments
Closed

hid_read not returning expected data (libusb) #556

VexedUXR opened this issue May 17, 2023 · 4 comments
Labels
duplicate This issue or pull request already exists libusb Related to libusb backend

Comments

@VexedUXR
Copy link

VexedUXR commented May 17, 2023

When using hid_read to receive data from the device (NZXT kraken x63) the expected value of the first two bytes is 0x11 (report id) and 0x01, however they arent always received. They are consistently received with the hidraw backend.

Explanation:
The NZXT kraken x63 periodically sends a device status packet with the report id of 0x75 and the first byte 0x02.
The command im sending it via hid_write consists of two bytes 0x10 (report id) and 0x01, this should make the device respond with a report id of 0x11 and the first byte 0x01, this dosent always happen, sometimes it takes a few reads (which makes sense, a few device status packets could be queued) but other times the response isnt received at all.
With the hidraw backend the response is always instantly received.

Program:

int main(int argc, char** argv)
{
    hid_device* dev = hid_open(0x1e71, 0x2007, NULL);

    unsigned char   buf[64] = {0};
    buf[0] = 0x10;
    buf[1] = 0x01;

    hid_write(dev, buf, 64);

    int ret_val;
    do
    {
        ret_val = hid_read(dev, buf, sizeof(buf));
        printf("read %d bytes. buf[0]=0x%x buf[1]=0x%x\n", ret_val, (int)buf[0], (int)buf[1]);
    } while( (ret_val != 64) || (buf[0] != 0x11) || (buf[1] != 0x01) );

    printf("Received response\n");
    hid_close(dev);
    hid_exit();

    return 0;
}

Example:

$ sudo ./backend_raw
read 64 bytes. buf[0]=0x11 buf[1]=0x1
Recived response

$ sudo ./backend_raw
read 64 bytes. buf[0]=0x11 buf[1]=0x1
Recived response

$ sudo ./backend_raw
read 64 bytes. buf[0]=0x11 buf[1]=0x1
Recived response

$ sudo ./backend_usb
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
...

$ sudo ./backend_usb
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x11 buf[1]=0x1
Recived response

$ sudo ./backend_usb
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
read 64 bytes. buf[0]=0x75 buf[1]=0x2
...

tested on linux and freebsd(libusb only) with hidapi v 13.1

Edit: formatting

@Youw
Copy link
Member

Youw commented May 17, 2023

A duplicate of #274 (and a known limitation).

@VexedUXR
Copy link
Author

oh, would the only solution be to use hidraw?
my main goal was to use this on freebsd

@VexedUXR VexedUXR closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2023
@Youw
Copy link
Member

Youw commented May 17, 2023

See: #274 (comment)
And: #274 (comment)

@VexedUXR
Copy link
Author

thanks :)

@mcuee mcuee added duplicate This issue or pull request already exists libusb Related to libusb backend labels May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists libusb Related to libusb backend
Projects
None yet
Development

No branches or pull requests

3 participants