Linux下复位USB设备

Linux下复位USB设备,第1张

概述  有时候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(

 

有时候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-filename\n");        return 1;    }    filename = argv[1];    fd = open(filename,O_WRONLY);    if (fd < 0) {        perror("Error opening output file");        return 1;    }    printf("resetting USB device %s\n",filename);    rc = ioctl(fd,USBDEVFS_reset,0);    if (rc < 0) {        perror("Error in ioctl");        return 1;    }    printf("reset successful\n");    close(fd);    return 0;}
总结

以上是内存溢出为你收集整理的Linux下复位USB设备全部内容,希望文章能够帮你解决Linux下复位USB设备所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1028048.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存