How to reset the USB device in Linux__linux

Source: Internet
Author: User
How to Reset the USB Device in LinuxBy ROMAN10 on May 4, 2011 • 7 COMMENTS
Tweet Share

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.