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)

 

请我喝咖啡

感谢支持,我会继续更新更有用的技术内容。

打赏二维码
请我喝咖啡 如果内容帮到了你,可以赞赏支持继续更新。
Category
Tags
Site statistics

本站现有文章218篇,共被浏览140523

本次响应耗时: 0.313s

当前来路IP: 18.97.14.83  

您是本站第: 255800 位访客!

本站已苟活: 

Commercial
开发者产品赞助位开放

适合 AI 工具、云服务、课程、开源项目和招聘团队。

查看合作方案
All hots
Article archiving
Mongona Radio
等待播放