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

usb 设备 复位的更多相关文章

  1. Linux下复位USB设备

    有时候USB设备出错,这时我们希望通过软件复位一下USB设备,可以参考下面这段代码: #include <stdio.h> #include <unistd.h> #inclu ...

  2. usb设备驱动描述,王明学learn

    usb设备驱动 本章主要内容包含以下:USB总线介绍,USB协议分析,USB系统架构 一.USB总线介绍 1.1USB发展史 USB(Universal Serial Bus)通用串行总线,是一种外部 ...

  3. USB协议-USB设备的枚举过程

    USB主机在检测到USB设备插入后,就要对设备进行枚举了.为什么要枚举?枚举就是从设备读取各种描述符信息,这样主机就可以根据这些信息来加载合适的驱动程序,从而知道设备是什么样的设备,如何进行通信等. ...

  4. USB设备架构

    USB设备,分为3层:1.底层为传送和接受数据的总线接口:2.中间层处理总线和不同端点的数据传输:3.最高层由串行总线设备提供.主要研究中间层. USB设备状态,主要研究外部可见状态. 1,连接态-- ...

  5. Linux下usb设备驱动详解

    USB驱动分为两块,一块是USB的bus驱动,这个东西,Linux内核已经做好了,我们可以不管,我们只需要了解它的功能.形象的说,USB的bus驱动相当于铺出一条路来,让所有的信息都可以通过这条USB ...

  6. USB设备被识别流程【转】

    转自:http://blog.csdn.net/myarrow/article/details/8286876 USB模块包括usb core,host,hub,device驱动,其中hub会启动一个 ...

  7. USB设备驱动之设备初始化(设备枚举)

    USB设备从接入HUB到正常工作之前.都属于设备枚举阶段.所谓设备枚举.就是让host控制器认识USB设备,并为其准备资源.建立好主机与设备间的数据传递机制. 该阶段的工作,是USB通信协议规定的,所 ...

  8. usb设备枚举过程

    USB主机在检测到USB设备插入后,就要对设备进行枚举了.为什么要枚举呢?枚举就是从设备读取一些信息,知道设备是什么样的设备,如何进行通信,这样主机就可以根据这些信息来加载合适的驱动程序.调试USB设 ...

  9. Linux自动共享USB设备:udev+Samba

    一.概述 公司最近要我实现USB设备插入Ubuntu后,自动共享到网络上,能像Windows共享一样(如\\192.168.1.10)访问里面的内容,不需要写入权限.当时听完这需求,我这新人表示惊呆了 ...

随机推荐

  1. Windows 如何录屏

    从Windows10开始,Windows开始自带了录屏功能(XBOX附带的).本来是方便游戏录制,但日常的录制也不在话下. 快捷键:Win + G 打开XBOX的录制工具 在打开录制工具后 Win + ...

  2. JAVA笔记整理(四),JAVA中的封装

    什么是封装 所谓的封装就是把数据项和方法作为一个独立的整体隐藏在对象的内部,具体的实施细节不对外提现,仅仅保留有限的外部接口,封装外的用户只能通过接口来进行操作.就好比开启一台电脑需要进行很多个步骤, ...

  3. 基于CentOS设置和使用Yum软件仓库

    参考:How To Set Up and Use Yum Repositories on a CentOS 6 VPS 参考:CentOS yum 源的配置与使用 介绍 Yum仓库是Linux软件仓库 ...

  4. Linux sudo(CVE-2019-14287)漏洞复现过程

    简述: 该漏洞编号是CVE-2019-14287. sudo是Linux系统管理指令,允许用户在不需要切换环境的前提下用其他用户的权限运行程序或命令,通常是以root身份运行命令,以减少root用户的 ...

  5. IOTA私有链简单搭建

    IOTA 参考:https://github.com/iotaledger/wallet 参考:https://github.com/iotaledger/iota.js 参考:https://git ...

  6. kvm虚拟机控制台登录配置

    vm虚拟机能否像xen虚拟机一样通过virsh console 一样采用字符界面进行linux虚拟机控制台呢,答案是肯定的,默认情况下该命令是不起作用的,需要修改相关文件才能实现. 本文出自:http ...

  7. python实现查找算法

    搜索是在一个项目集合中找到一个特定项目的算法过程.搜索通常的答案是真的或假的,因为该项目是否存在. 搜索的几种常见方法:顺序查找.二分法查找.二叉树查找.哈希查找 线性查找线性查找就是从头找到尾,直到 ...

  8. orm多表查询基于双下划线

    ###########基于双下划线的跨表查询(基于join实现的)############# key: 正向查询按字段,反向查询按表名小写 1.查询python这本书出版社的名字 ret = Book ...

  9. python中函数的定义、返回值以及参数的简要介绍

    一. 1.函数 定义:def关键字开头,空格之后接函数名称和圆括号(),后面紧跟‘:”. 函数是对功能的封装 语法: def 函数名(形参列表): 函数体(代码块,return) 调用: 函数名(实参 ...

  10. Error: EACCES: permission denied when trying to install ESLint using npm

    https://stackoverflow.com/questions/35954725/error-eacces-permission-denied-when-trying-to-install-e ...