Created
May 22, 2014 19:56
-
-
Save walac/581457aef5df47c23388 to your computer and use it in GitHub Desktop.
USB endpoint stall test for libusb-win32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <usb.h> | |
#include <stdio.h> | |
int main(int argc, char **argv) | |
{ | |
struct usb_bus *bus; | |
struct usb_device *dev = NULL; | |
usb_dev_handle *handle; | |
char dummy_data[5]; | |
int ret; | |
usb_init(); | |
usb_find_busses(); | |
usb_find_devices(); | |
bus = usb_get_busses(); | |
while (bus) { | |
dev = bus->devices; | |
while (dev) { | |
if (dev->descriptor.idVendor == 0x04d8 | |
&& dev->descriptor.idProduct == 0xfa2e) | |
goto found; | |
dev = dev->next; | |
} | |
bus = bus->next; | |
} | |
found: | |
if (!dev) { | |
fprintf(stderr, "Device not found.\n"); | |
return 1; | |
} | |
handle = usb_open(dev); | |
if (usb_set_configuration(handle, 1) < 0) | |
fprintf(stderr, "usb_set_configuration: %s\n", usb_strerror()); | |
if (usb_claim_interface(handle, 0) < 0) | |
fprintf(stderr, "usb_claim_interface: %s\n", usb_strerror()); | |
if (usb_set_altinterface(handle, 0) < 0) | |
fprintf(stderr, "usb_set_altinterface: %s\n", usb_strerror()); | |
if (usb_clear_halt(handle, 1) < 0) | |
fprintf(stderr, "usb_clear_halt: %s\n", usb_strerror()); | |
ret = usb_bulk_write(handle, 1, dummy_data, 5, 100); | |
if (ret < 0) | |
fprintf(stderr, "usb_bulk_write: %s\n", usb_strerror()); | |
else | |
printf("Written %d bytes\n", ret); | |
usb_release_interface(handle, 0); | |
usb_close(handle); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment