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.
sort of 非主流programmer. 喜歡美和思考。
作者:Edward_f0cus
鏈接:http://www.jianshu.com/p/57293f9be558
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。