How to Reset USB Device in Linux

by ROMAN10 on MAY 4, 2011 · 9 COMMENTS
 

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 hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root 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 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[];
fd = open(filename, O_WRONLY);
ioctl(fd, USBDEVFS_RESET, );
close(fd);
return;
}

Save the code above as reset.c, then compile the code using

gcc -o reset reset.c
32位arm:arm-linux-gnueabihf-gcc

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

最新文章

  1. 为什么eclipse中代码提示错误,但是项目目录却不提示错误
  2. LINQ延迟查询的例子
  3. UIApplication及UIWindow
  4. MySQL can’t specify target table for update in FROM clause
  5. android4.0 禁止横竖屏切换使用 android:configChanges=&quot;orientation|keyboardHidden&quot;无效的解决方法
  6. ajax提交表单序列化(serialize())数据
  7. js的函数返回值
  8. echarts的部署和使用
  9. [E::hts_idx_push] NO_COOR reads not in a single block at the end 10 -1
  10. 测试与发布(Beta版本)
  11. 【Java编程】Java中的字符串匹配
  12. HIT创业感言:只有长寿的企业才有持续价值
  13. kde钱包 忘记密码
  14. BZOJ4836 [Lydsy1704月赛]二元运算 分治 多项式 FFT
  15. Java web错误总结~
  16. SqlBulkCopy类(将一个表插入到数据库)
  17. Hdu2255 奔小康赚大钱(二分图最大权匹配KM算法)
  18. the-implementation-of-epoll
  19. Android开发懒人库 -- ButterKnife (转载)
  20. Mybatis 之动态代理

热门文章

  1. MYSQL安装与卸载(一)
  2. centos iptables 数据转发
  3. Android笔记(三十五) Android中AsyncTask
  4. 【DRF框架】序列化组件
  5. Spring 的 @Primary 注解
  6. JVM系列三:内存分配与回收策略
  7. linux网络编程之posix条件变量
  8. Gitlab,Git设置及使用前的准备
  9. CSP-S 2019 第二轮 退役记
  10. [TJOI2015]弦论(第k小子串)