Resetting USB devices

I’m not sure if it is just a bad motherboard, cable, USB device or just bad luck, but when I reboot the computer the UPS doesn’t appear. It’s not even seen in lsusb and of course that makes nut-server fail which makes nut-client complain that it cannot work out the UPS status.The solution was to unplug and plug the cable in then reset nut-server and all was good. But playing with cables seems so last century, surely there was a better way?

Some Googling showed up a way to Reset USB without a reboot but the directories the entry mentioned didn’t exist on my computer; though there was something very close to it. Perhaps that would work? A few tweaks later and I had a working UPS monitoring cable!

The changed script is below:

I’m not sure if it is just a bad motherboard, cable, USB device or just bad luck, but when I reboot the computer the UPS doesn’t appear. It’s not even seen in lsusb and of course that makes nut-server fail which makes nut-client complain that it cannot work out the UPS status.The solution was to unplug and plug the cable in then reset nut-server and all was good. But playing with cables seems so last century, surely there was a better way?

Some Googling showed up a way to Reset USB without a reboot but the directories the entry mentioned didn’t exist on my computer; though there was something very close to it. Perhaps that would work? A few tweaks later and I had a working UPS monitoring cable!

The changed script is below:

#!/bin/sh

SYSXHCI=/sys/bus/pci/drivers/xhci_hcd

if [ "$(id -u)" != 0 ] ; then
 echo This must be run as root!
 exit 1
fi

if ! cd $SYSXHCI ; then
 echo Weird error. Failed to change directory to $SYSXHCI
 exit 1
fi

for dev_id in ????:??:??.? ; do
 printf "${dev_id}" > unbind
 printf "${dev_id}" > bind
done

Thanks to Eli for the original idea which got me onto the right path.

 

 

 

Comments

7 responses to “Resetting USB devices”

  1. Steve Kemp Avatar

    It seems like you could have updated the original script to work on any of the available systems.

    For example:

    https://gist.github.com/skx/8999821

    1. Craig Avatar

      I was thinking of doing that but I only had the one directory type. It’s there on the gist for anyone that wants the “all directory” version, thanks!

      Oh, and I stopped some of the bashisms in it too.

  2. Tyler Janzen Avatar

    This worked like a charm for me running on Linux Mint 15 Olivia.

    Thanks 😉

  3. Ubu the Tech Guru Avatar

    what impact if any would this have on other usb devices connected to the system that did properly initialize? i’m having an issue with my steel series sensei always being registered upon boot up. sometimes it works and others it doesn’t. to solve it all i do is unplug it and plug it back in. I would love to not have to do this but i’m wondering if there’s any impact to any other usb devices like my usb webcams and controller.

    1. Craig Avatar

      I didn’t notice any problem with things such as my keyboard and mouse. I suspect it depends on what the device and driver do if something went away for a second or so.

Leave a Reply

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