重置ubuntu linux usb设备,断电后再上电方法

步骤1

vi usbreset.c

输入以下内容

/*重启usb硬件端口*/
#include 
#include 
#include 
#include 
#include 
#include 

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];//表示usb的ID

fd = open(filename, O_WRONLY);
if (fd < 0) {
    perror("Error opening output file");
    return 1;
}
printf("reset USB By wmfy808\n");
printf("Resetting USB device %s\n", filename);
rc = ioctl(fd, USBDEVFS_RESET, 0);//ioctl是设备驱动中,对I/O设备进行管理的函数USBDEVFS_RESET 是对usb设备进行断电重启
if (rc < 0) {
    perror("Error in ioctl");
    return 1;
}
printf("Reset successful\n");

close(fd);
return 0;

}

步骤2

然后执行

cc usbreset.c -o usbreset
chmod +x usbreset

lsusb|sed 's/":"//g'|awk '{print "/root/usbreset /dev/bus/usb/"$2"/"$4}'|sh