From akoana, 4 Months ago, written in Plain Text.
  1. /* usbreset -- send a USB port reset to a USB device */
  2. /*
  3.     Compile the program:
  4.  
  5.     $ cc usbreset.c -o usbreset
  6.  
  7.     Get the Bus and Device ID of the USB device you want to reset:
  8.  
  9.     $ lsusb
  10.     Bus 002 Device 003: ID 0fe9:9010 DVICO
  11.  
  12.     Make our compiled program executable:
  13.  
  14.     $ chmod +x usbreset
  15.  
  16.     Execute the program with sudo privilege; make necessary substitution for
  17.     <Bus>
  18.     and
  19.     <Device>
  20.     ids as found by running the
  21.     lsusb
  22.     command:
  23.  
  24.     $ sudo ./usbreset /dev/bus/usb/002/003
  25.  
  26.  
  27. */
  28. #include <stdio.h>
  29. #include <unistd.h>
  30. #include <fcntl.h>
  31. #include <errno.h>
  32. #include <sys/ioctl.h>
  33.  
  34. #include <linux/usbdevice_fs.h>
  35.  
  36.  
  37. int main(int argc, char **argv)
  38. {
  39.     const char *filename;
  40.     int fd;
  41.     int rc;
  42.  
  43.     if (argc != 2) {
  44.         fprintf(stderr, "Usage: usbreset device-filename,n  e.g:usbreset /dev/bus/usb/002/003n");
  45.         return 1;
  46.     }
  47.     filename = argv[1];
  48.  
  49.     fd = open(filename, O_WRONLY);
  50.     if (fd < 0) {
  51.         perror("Error opening output file");
  52.         return 1;
  53.     }
  54.  
  55.     printf("Resetting USB device %sn", filename);
  56.     rc = ioctl(fd, USBDEVFS_RESET, 0);
  57.     if (rc < 0) {
  58.         perror("Error in ioctl");
  59.         return 1;
  60.     }
  61.     printf("Reset successfuln");
  62.  
  63.     close(fd);
  64.     return 0;
  65. }
  66.  
  67.  

Replies to usbreset.c rss

Title Name Language When
Re: usbreset.c akoana text 4 Months ago.
captcha