usb 设备 复位
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[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
原文地址:https://www.cnblogs.com/Ph-one/p/11531847.html
- TensorFlow强化学习入门(0)——Q-Learning的查找表实现和神经网络实现
- 【云端架构】网站运维之CDN链接鉴权示例入门(PHP)
- 以太坊·单机多实例演示
- TensorFlow强化学习入门(1)——双臂赌博机
- CTF逆向--.NET与Python篇
- CTF逆向--安卓篇
- hackme.inndy.tw的19道web题解(下)
- hackme.inndy.tw的19道web题解(中)
- hackme.inndy.tw的19道web题解(上)
- CTF中RSA题型解题思路及技巧
- 技术解析 | Web缓存欺骗测试
- SSH僵尸主机挖矿木马预警
- 看我如何通过Tor Onion在Windows中执行远程Shell
- 某租车系统JAVA代码审计
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Android使用Volley框架定制PostUploadRequest上传文件
- Android实现横向滑动卡片效果
- 在jasmine beforeEach里修改UI元素的一个side effect
- Android实现头像上传功能
- 关于jasmine里debugElement.query和fixture.detectChanges的依赖关系
- 使用python批量转换文件编码为UTF-8的实现
- rxjs operator学习笔记
- python实现将两个文件夹合并至另一个文件夹(制作数据集)
- rxjs里使用from operator从一个generator里生成Observable
- 使用asyncScheduler进行Observable的延迟subscribe
- 解决flask接口返回的内容中文乱码的问题
- Android自定义控件实现带数值和动画的圆形进度条
- rxjs interval和take的混合使用
- Android自定义控件实现带文本与数字的圆形进度条
- 云函数Python依赖包安装,应用启动超时问题排查