#include <stdio.h>#include <usb.h>int main(int argc, char **argv) { struct usb_bus *bus; struct usb_bus *busses; struct usb_device *dev; usb_dev_handle *dev_handle; int c,i,a; char buf; int temp=0; usb_init(); usb_find_busses(); usb_find_devices(); for (bus=usb_busses;bus;bus=bus->next) { for (dev=bus->devices;dev;dev=dev->next) { //If this is our device (KORG K49 USB MIDI Keyboard Controller) if (dev->descriptor.idVendor==0x944 && dev->descriptor.idProduct==0xF01) { //Loop through all of the configurations for (c = 0; c < dev->descriptor.bNumConfigurations; c++) { //Loop through all of the interfaces for (i = 0; i < dev->config[c].bNumInterfaces; i++) { //Loop through all of the alternate settings for (a = 0; a < dev->config[c].interface[i].num_altsetting; a++) { //Check to see if this is the right interface (?) if (dev->config[c].interface[i].altsetting[a].bInterfaceClass == 1) { //Open the device, set the alternate setting, claim the interface and do your processing printf("Interface Found!\n"); temp=1; goto label1; } } } } } } } label1: if(temp) { if(!(dev_handle=usb_open(dev))) { fprintf(stderr,"Unable to open USB keyboard device\n"); return -1; } printf("KORG K49 USB MIDI Keyboard Controller found!\n"); usb_set_configuration(dev_handle,c); if(usb_claim_interface(dev_handle,i)) { fprintf(stderr,"Error claiming device interface\n"); usb_close(dev_handle); return -1; } if(usb_set_altinterface(dev_handle,a)) { fprintf(stderr,"Error setting device altinterface\n"); usb_close(dev_handle); return -1; } //test read if(usb_bulk_read(dev_handle,3,&buf,1,5000) != 1) { fprintf(stderr,"Error reading from device\n"); } usb_close(dev_handle); } else { printf("USB keyboard not found\n"); return 0; } return 0;}