Turning off a single usb device… again

前端 未结 3 1392
轮回少年
轮回少年 2020-12-25 13:23

I know that this topic has been discussed many times, but none of the answers helped me. For the record, i\'m running Debian.

The deal is: I bought an usb powered le

相关标签:
3条回答
  • 2020-12-25 14:07

    Turn off device ID 2-1:

    echo '2-1' |sudo tee /sys/bus/usb/drivers/usb/unbind

    Turn device ID 2-1 back on:

    echo '2-1' |sudo tee /sys/bus/usb/drivers/usb/bind

    In my case, using device ID 2-1 controls power to my usb stick, and as a consequence controls the light.

    • TIP: If they work for you in Debian, create an alias for them to make life easier for you later.

    Hope this helps, Su

    0 讨论(0)
  • 2020-12-25 14:12

    Try this code it works for me (Only for rooted)

     String[] cmdline = { "su", "-c", "echo '1-1' >/sys/bus/usb/drivers/usb/unbind" };
    try {
        Runtime.getRuntime().exec(cmdline);
    } catch (IOException e) {
        Log.e("MainActivity","Failed"+e);
    }
    

    and for bind again do this

        String[] cmdline = { "su", "-c", "echo '1-1' >/sys/bus/usb/drivers/usb/bind" };
    try {
        Runtime.getRuntime().exec(cmdline);
    } catch (IOException e) {
        Log.e("MainActivity","Failed"+e);
    }
    
    0 讨论(0)
  • 2020-12-25 14:16

    If all you want to do is reset a USB device to fix it once it gets into a broken state, then using the bind/unbind usbfs special files can be a bit of a pain (since device IDs can change, and they're a bit tricky to identify precisely if you don't want to rebind other devices). In this case I've found it much easier to use the vendor and product IDs given by lsusb with usb_modeswitch. For example, if I identify my wireless adapter using:

    $ lsusb
    Bus 001 Device 042: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]
    Bus 001 Device 035: ID 0409:005a NEC Corp. HighSpeed Hub
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    

    I can then reset the wireless adapter using:

    $ sudo usb_modeswitch -v 0x7392 -p 0x7811 --reset-usb
    

    If you have more than one device attached with the same vendor and product IDs then usb_modeswitch provides bus and device number flags. For the wireless adapter example above I'd add -b 1 -g 42 to the flags.

    0 讨论(0)
提交回复
热议问题