echo on > /sys/bus/usb/devices/usb2/power/control cat /sys/bus/usb/devices/usb2/idVendor cat /sys/bus/usb/devices/usb2/idProduct echo 2-0:1.0 > /sys/bus/usb/drivers/hub/unbind echo 1d6b 0003 > /sys/bus/usb/drivers/lvs/new_id echo 2-0:1.0 > /sys/bus/usb/drivers/lvs/bind echo 1 > /sys/bus/usb/drivers/lvs/2-0:1.0/enable_compliance什么意思
时间: 2023-07-17 11:53:40 浏览: 69
这是一组 Linux 命令,用于控制 USB 设备的电源和驱动程序。其中:
- `echo on > /sys/bus/usb/devices/usb2/power/control`:将 USB2 设备的电源控制设置为 “on”,以便在系统启动时打开设备。
- `cat /sys/bus/usb/devices/usb2/idVendor` 和 `cat /sys/bus/usb/devices/usb2/idProduct`:显示 USB2 设备的 Vendor ID 和 Product ID。
- `echo 2-0:1.0 > /sys/bus/usb/drivers/hub/unbind`:将 USB2 设备从 USB hub 中解绑。
- `echo 1d6b 0003 > /sys/bus/usb/drivers/lvs/new_id`:向 Linux USB Video Class 驱动程序注册一个新的 USB 设备 ID。
- `echo 2-0:1.0 > /sys/bus/usb/drivers/lvs/bind`:将 USB2 设备绑定到 Linux USB Video Class 驱动程序。
- `echo 1 > /sys/bus/usb/drivers/lvs/2-0:1.0/enable_compliance`:启用 USB2 设备的 USB 规范兼容性模式。
这些命令可以用于诊断和修复 USB 设备的问题,但需要谨慎使用,以免造成不可逆的损害。
相关问题
usb 3.0 echo on > /sys/bus/usb/devices/usb2/power/control cat /sys/bus/usb/devices/usb2/idVendor cat /sys/bus/usb/devices/usb2/idProduct echo 2-0:1.0 > /sys/bus/usb/drivers/hub/unbind echo 1d6b 0003 > /sys/bus/usb/drivers/lvs/new_id echo 2-0:1.0 > /sys/bus/usb/drivers/lvs/bind echo 1 > /sys/bus/usb/drivers/lvs/2-0:1.0/enable_compliance
这似乎是一组 Linux 命令,可以通过终端执行。首先,第一条命令是将 USB 3.0 设备的电源控制设置为“回声”模式。接下来两条命令是查看 USB 设备的厂商和产品 ID。第四条命令是将 USB hub 设备从驱动程序中解除绑定。第五条命令是将指定的 ID 添加到 LVS 驱动程序的设备列表中。最后一条命令是启用 LVS 驱动程序的指定 USB 设备的符合性。需要注意的是,这些命令可能需要 root 权限才能执行。
驱动文件中如何读/sys/bus/usb/devices文件信息
在 Linux 系统中,可以通过读取/sys/bus/usb/devices目录下的文件来获取 USB 设备的相关信息,包括设备的供应商 ID、产品 ID、序列号等。
具体方法如下:
1. 打开/sys/bus/usb/devices目录。
2. 遍历该目录下的所有子目录,每个子目录代表一个 USB 设备。
3. 在每个 USB 设备的子目录中,可以读取以下文件来获取设备信息:
- idVendor:设备的供应商 ID。
- idProduct:设备的产品 ID。
- serial:设备的序列号。
- manufacturer:设备制造商。
- product:设备名称。
以 Python 代码为例,可以实现以下功能:
```python
import os
usb_dir = '/sys/bus/usb/devices'
def get_usb_devices():
devices = []
for subdir in os.listdir(usb_dir):
dev_dir = os.path.join(usb_dir, subdir)
if os.path.isdir(dev_dir):
vendor_id = read_file(os.path.join(dev_dir, 'idVendor')).strip()
product_id = read_file(os.path.join(dev_dir, 'idProduct')).strip()
serial = read_file(os.path.join(dev_dir, 'serial')).strip()
manufacturer = read_file(os.path.join(dev_dir, 'manufacturer')).strip()
product = read_file(os.path.join(dev_dir, 'product')).strip()
if vendor_id and product_id:
devices.append({
'vendor_id': vendor_id,
'product_id': product_id,
'serial': serial,
'manufacturer': manufacturer,
'product': product
})
return devices
def read_file(file_path):
with open(file_path) as f:
return f.read()
if __name__ == '__main__':
devices = get_usb_devices()
print(devices)
```
该代码会输出当前系统中所有 USB 设备的供应商 ID、产品 ID、序列号、制造商和名称。