我最近更新了我的android手機到棉花糖。不幸的是,對我來說,這打破了我的Python代碼。連接在PyUSB中使用set_configuration時重置
使用PyUSB,我可以讓設備進入配件模式。不幸的是,我不能再讀/寫設備,因爲現在使用set_configuration()
重置連接,導致設備退出附件模式並重新進入MTP模式。
dev = list(usb.core.find(find_all=True))[0]
dev.ctrl_transfer(0xc0,51,data_or_wLength=2)
dev.ctrl_transfer(0x40,52,wIndex=0,data_or_wLength='SAMSUNG')
dev.ctrl_transfer(0x40,52,wIndex=1,data_or_wLength='SAMSUNG_Android')
dev.ctrl_transfer(0x40,52,wIndex=2,data_or_wLength='16DIGITSERIALNUM')
dev.ctrl_transfer(0x40,52,wIndex=3,data_or_wLength='AOA')
dev.ctrl_transfer(0x40,52,wIndex=4,data_or_wLength='Whatever')
dev.ctrl_transfer(0x40,52,wIndex=5,data_or_wLength='4')
dev.ctrl_transfer(0x40,53)
time.sleep(5)
dev = list(usb.core.find(find_all=True))[0]
dev.set_configuration() ## Aaaaaand we're back to MTP...
我找不到任何方法;沒有提到這個問題。我唯一能解決的問題就是直接學習C並直接使用libusb
,假設PyUSB
模塊是怪的......