0

I am running the program below which returns an error code(-1, LIBUSB_ERROR_IO, Bytes sent: 0) when trying to transfer the data. I am using the libusb-1.0 dll.

#include <stdio.h>
#include "inc/libusb.h"

int main(void) {
    libusb_device_handle *dev_handle;

    unsigned char buf[5] = {0x04, 0x00, 0x06, 0x06, 0x00};

    int r, bytes_sent = 0;

    if(libusb_init(NULL)) return 1;
    dev_handle = libusb_open_device_with_vid_pid(NULL, 0x1b1c, 0x0c04);
    libusb_claim_interface(dev_handle, 0);

    r = libusb_interrupt_transfer(dev_handle, 0x81, buf, 5, &bytes_sent, 0);

    printf("Return code: %d\nBytes sent: %d\n", r, bytes_sent);

    libusb_release_interface(dev_handle, 0);
    libusb_close(dev_handle);
    libusb_exit(NULL);

    return 0;
}

Also, I am not sure that I am using the correct endpoint address. These are some images from usbview: https://i.stack.imgur.com/rk2CX.png, https://i.stack.imgur.com/CK8n3.png. The first one shows the device I am trying to communicate with. Since not much information is provided from the device in the first image I use the information from the second image. I am right in assuming I need to use interrupt communication with this device, judging from the transfer type, under the endpoint descriptor?

Finally, is it possible that libusb might not be right for communicating with the specific device and I need to use another library?(eg. hidapi)

gkatev
  • 81
  • 1
  • 2
  • 7
  • What libusb backend do you use? Or do you maybe try to work without backend which does not work under Windows? – dryman May 23 '16 at 07:36
  • I am no actually sure. What do you mean by backend? For compiling I use mingw. Also, when I downloaded libusb there were two dlls in folders named MinGW32 and MinGW64. I used the 32 one since the 64 gave me a "file format not recognized" error – gkatev May 23 '16 at 10:30
  • With backend I mean a driver. Libusb on Windows needs a special driver like libusb0.sys (libusb-win32), libusbK.sys or WinUSB. Have you installed any inf File or used a InfWizard called tool? – dryman May 23 '16 at 11:33
  • No I have not. Which one of those would better serve me? Or is there really no difference? – gkatev May 23 '16 at 12:01
  • Since Microsoft offered its own interface and all open source backend projects seem to have died I recommend WinUSB. Also my personal experience is much better with WinUSB. An easy way to install and use them is Zadig. It automatically installs any backend you want so you can try them out as you see fit. This should resolve the issue. If it does I will write this as answer. If the error persists or others occur just follow up on this. – dryman May 23 '16 at 12:08
  • Hello, thanks for the help thus far. After installing winusb using zadig I don't the error and it seems like I am able to communicate with the device. However it now time-outs. While I am suspecting this may be a fault of mine regarding the device's communication protocol, could it be something else? Also, in Zadig I can see that the winusb driver is installed but there is an 'X' at WCID. I am guessing that that's not that important? – gkatev May 23 '16 at 12:47
  • If you get timeout as error this is not really an error per se but simply stating that the device has nothing to send. I suggest you put the transfer into a loop that breaks if bytes_sent > 0 and than (the PID/VID suggest its a barcode scanner) scan something. – dryman May 23 '16 at 13:08
  • Also if this is a HID barcode scanner with the WinUSB driver the HID functionality in Windows is lost. That is why WCID is no longer true I guess. If you want to let it remain as HID you should switch to hidapi as library. I didn't know that/if the device is a HID device. Just deinstall the driver in this case. – dryman May 23 '16 at 13:09
  • Well I am not trying to receive but send info to the device. It is a cpu cooler and I am trying to set some of its settings. It is actually a HID device from what I understand. Take a look at this page: http://forum.corsair.com/forums/showthread.php?t=120092. Is what I am trying to do possible with libusb or do I need to use hidapi? – gkatev May 23 '16 at 13:24
  • As I understand it this tutorial shows the real HID data so if you want to use this site I think libusb is the right choice. You could use hidapi too, but would have to change the data from this tutorial and with libusb you can take the data the way it is exlained there. I guess you have to read the tutorial in more detail. It says that you have to always send 64 bytes, the first byte is the length of the following payload and all unused bytes at the end are zeros. Try this out if the device accepts it. – dryman May 23 '16 at 14:16
  • 1
    Well I am not sure what the problem was with libusb, but it happily works hidapi, so, I guess all is well.. Also, for anyone reading this, with hidapi, for this specific device, I had to add a zero before the number of bytes the device is to receive and with that leading zero, the total number of bytes I sent was 65. Thanks for the help dryman! – gkatev May 23 '16 at 14:24
  • Ok if it works with hidapi everythings fine. Happy Hacking I guess. :) – dryman May 23 '16 at 15:03

0 Answers0