前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >树莓派固定usb设备名称

树莓派固定usb设备名称

作者头像
用户2458545
发布2022-09-07 11:44:19
1.4K0
发布2022-09-07 11:44:19
举报
文章被收录于专栏:阿牛的牙阿牛的牙
代码语言:javascript
复制
# 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摄像头为例:

代码语言:javascript
复制
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)
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020年5月24日 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档