linux控制USB的綁定/解綁
阿新 • • 發佈:2017-10-12
auth drive ebo info nat 非主流 sort and get
作者:Edward_f0cus
鏈接:http://www.jianshu.com/p/57293f9be558
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請註明出處。
linux控制USB的綁定/解綁
http://www.jianshu.com/p/57293f9be558
今天工作中遇到一個問題, 要用代碼實現USB的enable和disable. 谷歌了一番, 最終找到理想答案, 我在這裏做一個簡短porting. 來源:墻外某博
- 首先通過lsusb -t來查看USB端口信息:
(註: 你可以插拔一下要控制的USB, 來確定到底是哪個BUS的哪個port.)/: Bus 02.Port 1: Dev 1, class="root_hub", Driver=ehci-pci/3p, 480M |__ Port 1: Dev 2, If 0, class="hub", Driver=hub/8p, 480M |__ Port 6: Dev 78, If 0, class="vend"., Driver=, 480M |__ Port 6: Dev 78, If 1, class="vend"., Driver=usbfs, 480M |__ Port 6: Dev 78, If 2, class="comm"., Driver=cdc_acm, 480M |__ Port 6: Dev 78, If 3, class="data", Driver=cdc_acm, 480M |__ Port 6: Dev 78, If 4, class="comm"., Driver=cdc_acm, 480M |__ Port 6: Dev 78, If 5, class="data", Driver=cdc_acm, 480M |__ Port 6: Dev 78, If 6, class="comm"., Driver=cdc_acm, 480M |__ Port 6: Dev 78, If 7, class="data", Driver=cdc_acm, 480M /: Bus 01.Port 1: Dev 1, class="root_hub", Driver=ehci-pci/3p, 480M |__ Port 1: Dev 2, If 0, class="hub", Driver=hub/6p, 480M |__ Port 1: Dev 6, If 0, class="HID", Driver=usbhid, 1.5M |__ Port 1: Dev 6, If 1, class="HID", Driver=usbhid, 1.5M |__ Port 3: Dev 9, If 0, class="HID", Driver=usbhid, 1.5M
在這裏我要操作BUS 02的port 1下的port 6. - 執行以下command去unbind這個USB:
其實用不用tee都行, 直接重定向也可以. 需要註意的是, 所要echo的字符串:echo ‘2-1.6‘ | sudo tee /sys/bus/usb/drivers/usb/unbind
"$bus_num"-"$port1_num"."$port2_num"
大概是這麽個format. - 重新bind的command, 只需要把上面command中的unbind改成bind.
echo ‘2-1.6‘ | sudo tee /sys/bus/usb/drivers/usb/bind
That‘s it.
Knowledge from work ? 著作權歸作者所有 舉報文章 關註 Edward_f0cus寫了 15596 字,被 17 人關註,獲得了 34 個喜歡
sort of 非主流programmer. 喜歡美和思考。如果覺得我的文章對您有用,請隨意贊賞。您的支持將鼓勵我繼續創作!
作者:Edward_f0cus
鏈接:http://www.jianshu.com/p/57293f9be558
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請註明出處。
linux控制USB的綁定/解綁