Reset USB device in linux

I had old UPS with serial port which was connected using Profilic USB to serial adapter. Sometimes this USB dongle had frozen and need to be restated – re-attached. This can be done in linux using IOCTL.

Simple C code from stackowerflow:

#include 
#include 
#include 
#include 
#include 
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;
}

Device id (argv1) need to be passed like this:

# Bus 00X Device 00Y: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
DEV=`lsusb| grep '067b:2303' |awk {'print "/dev/bus/usb/"$2"/"$4'}|cut -f1 -d:`
echo "Reseting usb device $DEV"
usbreset $DEV

https://nextcloud.iwik.org/s/usbreset

Note: This is working for physical servers, not for USB devices pass-through to VM.

Leave a Reply

Your email address will not be published. Required fields are marked *