Re: libusb_control_transfer returns LIBUSB_ERROR_IO and GetLastError()=1186 (Win7)

Xiaofan Chen <[email protected]> Mon, 10 Aug 2015 21:29:05 +0800
Newsgroups gmane.comp.lib.libusb.devel.windows
Message-ID <CAGjSPUCHaYrDcqzS8A4ysuE_p1We7kuCuYvFVyAm+fPS5bmj-w@mail.gmail.com>
On Wed, Aug 5, 2015 at 10:56 PM, licedey <[email protected]> wrote:
> Thank you for the reply. I've tried hidapi library, looks like it works, but
> hid_write() call return "Invalid Parameter" error. However I am using
> sources from test project from their site.
> How to fix please? Maybe it my USB keyboard error, because of no lib can
> read/write to it. I've tried with libusb, Windows HID API, hidapi library.
> No success everywhere.
>
> memset(buf,0,sizeof(buf));
>
> // Toggle LED (cmd 0x80). The first byte is the report number (0x1).
> buf[0] = 0x1;
> buf[1] = 0x81;
> res = hid_write(handle, buf, 17);
> if (res < 0) { // returns -1
>         printf("Unable to write()\n");
>         printf("Error: %ls\n", hid_error(handle));
> }

No you can not use HIDAPI or libusb HID backend to talk to
a real USB keyboard under Windows. Both HIDAPI and
libusb HID backend are based on Windows HIDAPI which
is not meant for USB keyboard and mouse.

Why do you want to do that? For learning? Then keyboard
or USB drive are not good for learning. Buy a USB development
kit and use that.

If you really want to use the keyboard, then you may have to
replace the keyboard driver with WinUSB and you can
use libusb-1.0 API to talk to it (not HIDAPI).



-- 
Xiaofan

------------------------------------------------------------------------------