How to Reset the USB Device in LinuxBy ROMAN10 on May 4, 2011 • 7 COMMENTS
USB devices are anywhere nowadays, even many embedded devices replace the traditional serial with USB devices. However, I experienced that USB devices hang from time to time. In most cases, a manual unplug and replug would solve the issue. Actually, USB reset can simulate the unplug and replug operation.
The device path for your USB device. Enter the command Lsusb'll give you something similar as below,
Bus 008 Device 001:id 1d6b:0001 Linux Foundation 1.1 root hub bus
007 Device 001:id 1d6b:0001 Linux Foundation 1.1 r Oot Hub bus
006 Device 002:id 04b3:310c IBM Corp. Wheel Mouse bus
001 Device 001:id 1d6b:0002 Linux Foundation 2 .0 Root Hub Bus
004 Device 002:id 0a5c:2145 Broadcom Corp.
Bus 005 Device 001:id 1d6b:0001 Linux Foundation 1.1 root Hub
Use the IBM Wheel Mouse as a example, the device node for it is/dev/bus/usb/006/002, where 006 are the bus number, and 00 2 is the device number.
Second, apply IOCTL operation to reset the device. This are done in C code,
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/usbdevice_fs.h>
void Main (int argc, char **argv)
{
const char *filename;
int FD;
filename = argv[1];
FD = open (filename, o_wronly);
IOCTL (FD, Usbdevfs_reset, 0);
Close (FD);
Return
}
Save the code above as RESET.C, then compile the code using
Gcc-o Reset Reset.c
This is produce the a binary named reset. Again, using the wheel mouse as an example, execute the following commands,
sudo./reset/dev/bus/usb/006/002
Can take a look at the
Tail-f/var/log/messages
On our Ubuntu desktop, the last line reads,
May 4 16:09:17 roman10 kernel: [1663.013118] USB 6-2:
reset down Speed USB device using UHCI_HCD and address 2
This reset operation is effectively the same as to you unplug and replug a USB device.
For another method of the reset USB using LIBUSB, please refer here
reference:http://forums.x-plane.org/index.php?app=downloads&showfile=9485.