linux env python中的usb自动检测 [英] usb automatic detection in python for linux env

查看:33
本文介绍了linux env python中的usb自动检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 python 中使用轮询命令(glob('/dev/tty[A-Za-z]*')) 以定期为我的应用程序检测连接到我的 linux pc 的 USB 设备.有什么方法可以检测自动连接的 USB 设备?

I'm using polling command(glob('/dev/tty[A-Za-z]*')) in python to detect usb devices connected to my linux pc in regular interval for my application. Is there any way to detect usb devices connected automatically?

推荐答案

我建议使用 libudev 并创建一个 udev 监控对象来检测热插拔设备.这里是您了解 libudev 及其监控功能的起点:

I'd suggest using libudev and creating a udev monitor object to detect hotplugged devices. Here is a starting point for you to learn about libudev and its monitor feature:

https://www.freedesktop.org/software/systemd/man/libudev.html

可能已经有一个很好的 Python 库包装了 udev,因此您无需编写 C 代码即可使用它的功能.

There might be a good Python library already that wraps udev so you can use its features without writing C code.

这篇关于linux env python中的usb自动检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆