I'm creating a program that reads in input from a midi controller using libusb. How do I properly call libusb_bulk_transfer? Currently I'm receiving the error "LIBUSB_ERROR_NOT_FOUND" every time, and the data that I receive is "P".
I've swapped out the function 'libusb_bulk_transfer' with 'libusb_interrupt_transfer' but I still receive the same error: LIBUSB_ERROR_NOT_FOUND
Below are the libraries that I currently have included
#include <stdlib.h>
#include <stdio.h>
#include <libusb-1.0/libusb.h>
Below is main function that finds all of the usb devices and calls the function that is causing me issues: printDeviceUsbInput(devices[i]); For all I know, the main function is working fine. I removed the error checking to make the code shorter
int main(int argc, char *argv[])
{
libusb_device **devices;
libusb_context *context = NULL;
size_t list;
size_t i;
int returnValue;
returnValue = libusb_init(&context);
list = libusb_get_device_list(context, &devices);
printf("There are %zu devices found \n\n", list);
for (i = 0; i < list; i++)
{
printDeviceUsbInput(devices[i]);
//printDevices(devices[i]);
}
libusb_free_device_list(devices, 1);
libusb_exit(context);
return 0;
}
Below is the function that finds the midi keyboard device and attempts to print out the midi input. AKA the function that is causing me problems. I was inspired by this code: http://libusb.sourceforge.net/api-1.0/libusb_io.html
I also removed the error checking to make the function shorter.
void printDeviceUsbInput(libusb_device *device)
{
struct libusb_device_descriptor deviceDescriptor;
int returnValue;
returnValue = libusb_get_device_descriptor(device, &deviceDescriptor);
if(deviceDescriptor.idProduct == 49)
{
printf("Keyboard found\n\n");
unsigned char data[4];
int actual_length;
libusb_device_handle *deviceHandle;
returnValue = libusb_open(device, &deviceHandle);
while(1)
{
returnValue = libusb_bulk_transfer(deviceHandle, LIBUSB_ENDPOINT_IN,data, sizeof(data), &actual_length, 0);
printf("Data: %s\n\n", data);
printf("returnValue: %s\n\n", libusb_error_name(returnValue));
}
}
}
I expect that the call to libusb_bulk_transfer will return 0, and that the value of the variable data will change every-time I press a key on the midi keyboard.