最終更新:2017-06-01 (木) 15:14:52 (2521d)  

libusb-0.1/サンプルコード
Top / libusb-0.1 / サンプルコード

http://penguin.tantin.jp/hard/libusbについて.html

メモ

  • ドキュメントをビルドすると入ってる
    struct usb_bus *busses;
    
    usb_init();
    usb_find_busses();
    usb_find_devices();
    
    busses = usb_get_busses();
    struct usb_bus *bus;
    int c, i, a;
    
    /* ... */
    
    for (bus = busses; bus; bus = bus->next) {
    	struct usb_device *dev;
    
    	for (dev = bus->devices; dev; dev = dev->next) {
    		/* Check if this device is a printer */
    		if (dev->descriptor.bDeviceClass == 7) {
    			/* Open the device, claim the interface and do your processing */
    			...
    		}
    
    		/* 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 if this interface is a printer */
    					if (dev->config[c].interface[i].altsetting[a].bInterfaceClass == 7) {
    						/* Open the device, set the alternate setting, claim the interface and do your processing */
    						...
    					}
    				}
    			}
    		}
    	}
    }
  • libusb-0.1/testlibusb.c

ビルド

  • gcc test.c -lusb && sudo ./a.out

処理

初期化

開く