Created
June 18, 2019 08:16
-
-
Save Mohamedemad4/db794676f00ad872e4684fb56c5f1709 to your computer and use it in GitHub Desktop.
switch usbs in a chosen order ,can help if u have multipule USB devices with no uniq features .use lsusb -t ,to view the USB ports and their numbers ,made for the rpi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#based on:https://github.com/mvp/uhubctl | |
import os | |
import time | |
def turnthemAlloff(): | |
os.system("./uhubctl -a off -p 4") | |
os.system("./uhubctl -a off -p 3") | |
os.system("./uhubctl -a off -p 5") | |
time.sleep(3) | |
os.system("./uhubctl -a off -p 4") | |
os.system("./uhubctl -a off -p 3") | |
os.system("./uhubctl -a off -p 5") | |
time.sleep(4) | |
os.system("./uhubctl -a off -p 4") | |
os.system("./uhubctl -a off -p 3") | |
os.system("./uhubctl -a off -p 5") | |
time.sleep(5) | |
def doesPortExist(port): | |
if 'Port {0}'.format(port) in os.popen("lsusb -t").read(): | |
return True | |
return False | |
def turnPortOn(port): | |
os.popen("./uhubctl -a on -p {0}".format(port)).read() | |
if doesPortExist(port): | |
return True | |
else: | |
return turnPortOn(port) #unregulated tail recurssion FTW | |
print(os.popen("lsusb -t").read()) | |
turnthemAlloff() | |
turnPortOn(4) | |
turnPortOn(3) | |
turnPortOn(5) | |
print(os.popen("lsusb -t").read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment