usb_reset.c
Go to the documentation of this file.
1 /* usbreset -- send a USB port reset to a USB device */
2 
3 /*
4  * Copyright (c) 2014, JSK Robotics Lab, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * * Neither the name of the Willow Garage, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  * Author: Ryohei Ueda (ueda@jsk.t.u-tokyo.ac.jp)
32  */
33 
34 #include <stdio.h>
35 #include <unistd.h>
36 #include <fcntl.h>
37 #include <errno.h>
38 #include <sys/ioctl.h>
39 
40 #include <linux/usbdevice_fs.h>
41 
42 
43 int main(int argc, char **argv)
44 {
45  const char *filename;
46  int fd;
47  int rc;
48 
49  if (argc != 2) {
50  fprintf(stderr, "Usage: usbreset device-filename\n");
51  return 1;
52  }
53  filename = argv[1];
54 
55  fd = open(filename, O_WRONLY);
56  if (fd < 0) {
57  perror("Error opening output file");
58  return 1;
59  }
60 
61  printf("Resetting USB device %s\n", filename);
62  rc = ioctl(fd, USBDEVFS_RESET, 0);
63  if (rc < 0) {
64  perror("Error in ioctl");
65  return 1;
66  }
67  printf("Reset successful\n");
68 
69  close(fd);
70  return 0;
71 }
int main(int argc, char **argv)
Definition: usb_reset.c:43


openni2_camera
Author(s): Julius Kammerl
autogenerated on Wed Feb 3 2021 03:18:41