]>
code.delx.au - monosys/blob - hacks/usb-reset
9 if not sys
.platform
.startswith("linux"):
10 print >>sys
.stderr
, "Sorry, this tool requires Linux"
14 search_usb_id
= sys
.argv
[1].lower()
16 print >>sys
.stderr
, "Usage: %s vendorid:devid" % sys
.argv
[0]
17 print >>sys
.stderr
, "\nThis tool will reset all USB devices with the given ID (eg 1f4d:a803)"
21 USBDEVFS_RESET
= 21780
25 p
= subprocess
.Popen(["lsusb"], stdout
=subprocess
.PIPE
)
28 usb_id
= line
[5].lower()
29 if usb_id
!= search_usb_id
:
32 dev
= line
[3].replace(":", "")
34 filename
= "/dev/bus/usb/%s/%s" % (bus
, dev
)
35 print "Resetting", filename
, "...",
37 fd
= os
.open(filename
, os
.O_WRONLY
)
38 ret
= fcntl
.ioctl(fd
, USBDEVFS_RESET
, 0)
40 print >>sys
.stderr
, "\nError in ioctl:", ret