In the spirit of sharing, I modified the usbreset
code provided, in Tai's answer above, to accept parameters like you get from lsusb
(in addition). That way it can be invoked conveniently by
DEVNUMS=`lsusb | grep -i webcam | tr -d : | awk '{print $2, $4;}'`
/home/xyz/cam/usbreset $DEVNUMS
which turns, for example, into
/home/xyz/cam/usbreset 001 018
The code is at the end.
I found the Pi USB webcam driver crashed often, but this is a way to recover it. It was easiest to make the executable be su root.
void main(int argc, char **argv)
{
char devicename[1024];
const char *filename = devicename;
int fd;
if ( 2 > argc || 3 < argc ) {
printf("Give USB device name as parameter\n");
exit(1);
}
if ( 2 == argc )
filename = argv[1];
else
sprintf( devicename, "/dev/bus/usb/%s/%s", argv[1], argv[2] );
printf( "Resetting USB device '%s'\n", filename );
fd = open(filename, O_WRONLY);
if (fd == -1) {
perror("USB device open failed");
exit(2);
}
if (ioctl(fd, USBDEVFS_RESET, 0) == -1) {
// Don't care! It usually does, when we need to reset it.
//perror("USBDEVFS_RESET device ioctl failed");
//exit(3);
}
close(fd);
}