usb 设备 复位
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 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
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 设备 复位的更多相关文章
- Linux下复位USB设备
有时候USB设备出错,这时我们希望通过软件复位一下USB设备,可以参考下面这段代码: #include <stdio.h> #include <unistd.h> #inclu ...
- usb设备驱动描述,王明学learn
usb设备驱动 本章主要内容包含以下:USB总线介绍,USB协议分析,USB系统架构 一.USB总线介绍 1.1USB发展史 USB(Universal Serial Bus)通用串行总线,是一种外部 ...
- USB协议-USB设备的枚举过程
USB主机在检测到USB设备插入后,就要对设备进行枚举了.为什么要枚举?枚举就是从设备读取各种描述符信息,这样主机就可以根据这些信息来加载合适的驱动程序,从而知道设备是什么样的设备,如何进行通信等. ...
- USB设备架构
USB设备,分为3层:1.底层为传送和接受数据的总线接口:2.中间层处理总线和不同端点的数据传输:3.最高层由串行总线设备提供.主要研究中间层. USB设备状态,主要研究外部可见状态. 1,连接态-- ...
- Linux下usb设备驱动详解
USB驱动分为两块,一块是USB的bus驱动,这个东西,Linux内核已经做好了,我们可以不管,我们只需要了解它的功能.形象的说,USB的bus驱动相当于铺出一条路来,让所有的信息都可以通过这条USB ...
- USB设备被识别流程【转】
转自:http://blog.csdn.net/myarrow/article/details/8286876 USB模块包括usb core,host,hub,device驱动,其中hub会启动一个 ...
- USB设备驱动之设备初始化(设备枚举)
USB设备从接入HUB到正常工作之前.都属于设备枚举阶段.所谓设备枚举.就是让host控制器认识USB设备,并为其准备资源.建立好主机与设备间的数据传递机制. 该阶段的工作,是USB通信协议规定的,所 ...
- usb设备枚举过程
USB主机在检测到USB设备插入后,就要对设备进行枚举了.为什么要枚举呢?枚举就是从设备读取一些信息,知道设备是什么样的设备,如何进行通信,这样主机就可以根据这些信息来加载合适的驱动程序.调试USB设 ...
- Linux自动共享USB设备:udev+Samba
一.概述 公司最近要我实现USB设备插入Ubuntu后,自动共享到网络上,能像Windows共享一样(如\\192.168.1.10)访问里面的内容,不需要写入权限.当时听完这需求,我这新人表示惊呆了 ...
随机推荐
- Access denied for user 'test'@'%' to database 'mysql'
1.问题描述 今天使用MySQL新建了一个用户,此处假设为test用户,用来作为某安装软件的配置用户(会新建大量的表及视图) mysql> create user 'test'@'%' iden ...
- 解决npm安装时出现run `npm audit fix` to fix them, or `npm audit` for details 的问题
npm audit fix npm audit fix --force npm audit 按照顺序一一运行亲测完全可用如果还是不行的话,可以把node_modules和package-lock.js ...
- Window Server 2008 概述
Windows历史版本 Windows工作站发展历史 Windows95——>Windows98——>Windows2000——>WindowsXP——>Vista——> ...
- Go语言中的IO操作、Flag包以及urfave/cli命令行框架
一.格式化输入和输出 1.从终端获取用户的输入 fmt.Scanf 空格作为分隔符,占位符和格式化输出的一致 fmt.Scan 从终端获取用户的输入,存储在Scanln中的参数里,空格和换行符作为 ...
- ubuntu---记录.重装电脑之设置电脑信息
(1)设置网络(2)安装一个中文输入法(3)CUDA+驱动+cuDNN+添加到系统环境中(4)禁止内核更新(5)安装好opencv之后,查看安装的版本(6)查看自带的python版本(7)设置系统里p ...
- 04-Dockerfile介绍与使用
什么是dockerfileDockerfile是由一系列命令和参数构成的脚本,这些命令用一基础镜像并最终创建一个新的镜像.1.对于开发人员:可以为开发团队提供一个完全一致的开发环境.2.对于测试人员: ...
- Mysql-Percona mysql5.7简单安装
Mysql-Percona mysql5.7简单安装 一.什么是Percona 单从mysql的角度来讲,可以把Percona理解为mysql的一个分支,因为mysql的源码是开源的,Percona就 ...
- Centos 改ssh 端口
1.修改配置文件:/etc/ssh/sshd_config 2.修改 #Port 22 把前面的#注释删掉,然后添加一个Port XXXX 定义一个自己的.例如我喜欢 Port 22333 3.修改后 ...
- php流程控制之if else语法
php流程控制之if else语法 if和else语法 这是一个非常重要的章节,也是PHP当中的一个重要的语法. [注意]我对这个语法的定义级别为:默写级别.也就是你需要,闭着眼睛,都能够写出来的东西 ...
- 简单了解Web Workers API
1. 为什么使用Web Workers API 通过使用该API,web应用程序可以独立于主线程,运行一个单独的线程来处理脚本. 可以在独立的线程中解决耗时较长的任务,避免主线程阻塞. 2. 应用 1 ...