适用于linux env的python中的usb自动检测 [英] usb automatic detection in python for linux env
问题描述
我在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
可能已经有一个包装了udev的优秀Python库,因此您无需编写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屋!