How to Reset USB Device in Linux
来源:互联网 发布:c java md5加密解密 编辑:程序博客网 时间:2024/05/17 08:33
本文转载至:http://www.roman10.net/how-to-reset-usb-device-in-linux/
USB devices are anywhere nowadays, even many embedded devices replace the traditional serial devices with usb devices. However, I experienced that USB devices hang from time to time. In most cases, a manual unplug and replug will solve the issue. Actually, usb reset can simulate the unplug and replug operation.
First, get the device path for your usb device. Enter the command lsusb will give you something similar as below,
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hubBus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hubBus 006 Device 002: ID 04b3:310c IBM Corp. Wheel MouseBus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hubBus 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 an example, the device node for it is /dev/bus/usb/006/002, where 006 is the bus number, and 002 is the device number.
Second, apply ioctl operation to reset the device. This is 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 will 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
You can take a look at the message by,
tail -f /var/log/messages
On my Ubuntu desktop, the last line reads,
May 4 16:09:17 roman10 kernel: [ 1663.013118] usb 6-2:reset low speed USB device using uhci_hcd and address 2
This reset operation is effectively the same as you unplug and replug a usb device.
For another method of reset usb using libusb, please refer here
Reference: http://forums.x-plane.org/index.php?app=downloads&showfile=9485.
- How to reset usb device in linux
- How to Reset USB Device in Linux
- How to Reset USB Device in Linux–using libusb
- How to programatically unplug & replug an USB device in linux?
- how to use usb device in linux version 3.00.14(1)-release (i386-redhat-linux-gnu)
- How to write a Linux USB Device Driver
- How to install linux with a usb device
- How to use IO BAR in linux PCIe device driver
- how to make usb composite device
- how to reset sys password in oracle
- How to reset password in ubuntu
- How to reset your password in Ubuntu
- How to enable USB selective suspend and system wake in the UMDF driver for a USB device
- How to restart USB device(如何重启USB设备)
- How to Use WinUSB to Communicate with a USB Device
- How To: Reset Identity column in SQL Server
- [转!]How to reset your password in Ubuntu
- How to burn Linux Kernel into nor flash and rootfs in USB stick at Mindspeed c1k
- EditPlus添加到右键菜单
- checkText输入框可输入字符个数提示
- 00-自测2. 素数对猜想 (20)
- zTree+PHP
- CSR蓝牙芯片开发
- How to Reset USB Device in Linux
- 新年开工第一天
- 电子商务系统的设计与实现(十一):数据库设计
- 百度地图3.3带搜索功能
- JQUERY校验
- IOS Category不要重写原有类方法
- Android类库打包方法探究
- 从程序员到技术总监,分享10年开发经验
- pat1015 Reversible Primes