mongona

mongona
-- --
正在获取天气

树莓派固定usb设备名称

 

# path: /etc/udev/rules.d
# file: devices.rules

SUBSYSTEM=="video*", ATTR{index}=="0", KERNELS=="1-1.1:1.0", MODE="0666", SYMLINK+="camera0", OPTIONS+="last_rule"
SUBSYSTEM=="video*", ATTR{index}=="0", KERNELS=="1-1.2:1.0", MODE="0666", SYMLINK+="camera1", OPTIONS+="last_rule"
SUBSYSTEM=="video*", ATTR{index}=="0", KERNELS=="1-1.3:1.0", MODE="0666", SYMLINK+="camera2", OPTIONS+="last_rule"
SUBSYSTEM=="video*", ATTR{index}=="0", KERNELS=="1-1.4:1.0", MODE="0666", SYMLINK+="camera3", OPTIONS+="last_rule"

 以USB摄像头为例:

import pyudev


def observe_camera(self):
    context = pyudev.Context()
    monitor = pyudev.Monitor.from_netlink(context)
    monitor.filter_by(subsystem='video4linux')  # Remove this line to listen for all devices.
    monitor.start()
    cmd = """
            for dev in `find /dev -iname 'video*' -printf "%f\n"`
            do
              v4l2-ctl --list-formats --device /dev/$dev | \
                grep -qE '\[[0-9]\]' && \
                echo $dev
            done
        """
    for device in iter(monitor.poll, None):
        # I can add more logic here, to run only certain kinds of devices are plugged.
        _path = device.device_path
        action = device.action  # add remove
        camera = list(device.device_links)[0]
        if not camera.startswith('/dev/camera'):
            continue
        if '1-1.1:1.0' in _path:
            location = 'usb—3.0_上'
        elif '1-1.2:1.0' in _path:
            location = 'usb-3.0_下'
        elif '1-1.3:1.0' in _path:
            location = 'usb-2.0_上'
        elif '1-1.4:1.0' in _path:
            location = 'usb-2.0_下'
        else:
            continue
        print(camera)

 

7
0
富强,民主,文明,和谐,自由,平等,公正,法治,爱国,敬业,诚信,友善。
打赏二维码