/* * testlibusb.c * * Test suite program */ #include #include #include const int usb_vendor = 0x147e; const int usb_devid = 0x2016; const int usb_endpoint = 0x81; #define bufsize 64 struct usb_device *finddev() { struct usb_bus *bus; for (bus = usb_busses; bus; bus = bus->next) { struct usb_device *dev; for (dev = bus->devices; dev; dev = dev->next) { if (dev->descriptor.idProduct == usb_devid && dev->descriptor.idVendor == usb_vendor) { return dev; } } } return NULL; } int main() { struct usb_device *dev; struct usb_dev_handle *udev; unsigned char buf[bufsize] = {0}; int status; usb_init(); usb_find_busses(); usb_find_devices(); dev = finddev(); if (dev == NULL) { fprintf(stderr, "Device %04x:%04x not found\n", usb_vendor, usb_devid); exit(1); } udev = usb_open(dev); if (udev == NULL) { abort(); } usb_set_configuration(udev, 1); if (usb_claim_interface(udev, 0) != 0) { perror("usb_claim_interface"); exit(1); } status = usb_bulk_write(udev, 0x02, buf, bufsize, 1000); if (status < 0){ perror("usb_bulk_write"); exit(1); } char cbuf[1] = {0x80}; usb_control_msg(udev, 0x40, 0x0c, 0x00, 0x0b, cbuf, 1, 1000); usb_control_msg(udev, 0x40, 0x0c, 0x00, 0x0b, cbuf, 1, 1000); while (1) { status = usb_bulk_read(udev, usb_endpoint, buf, bufsize, 1000); if (status < 0){ //fprintf(stderr, "Error %d: %s\n", stat); perror("usb_bulk_read"); exit(1); } fwrite(buf, 1, bufsize, stdout); } usb_close(udev); return 0; }