Linux下复位USB设备
发布时间:2020-12-14 01:27:35 所属栏目:Linux 来源:网络整理
导读:? 有时候USB设备出错,这时我们希望通过软件复位一下USB设备,可以参考下面这段代码: ? #include stdio.h#include unistd.h#include fcntl.h#include errno.h#include sys/ioctl.h#include linux/usbdevice_fs.hint main(int argc,char **argv){ const char
? 有时候USB设备出错,这时我们希望通过软件复位一下USB设备,可以参考下面这段代码: ? #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <sys/ioctl.h> #include <linux/usbdevice_fs.h> int main(int argc,char **argv) { const char *filename; int fd; int rc; if (argc != 2) { fprintf(stderr,"Usage: usbreset device-filenamen"); return 1; } filename = argv[1]; fd = open(filename,O_WRONLY); if (fd < 0) { perror("Error opening output file"); return 1; } printf("Resetting USB device %sn",filename); rc = ioctl(fd,USBDEVFS_RESET,0); if (rc < 0) { perror("Error in ioctl"); return 1; } printf("Reset successfuln"); close(fd); return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |