在python中获取友好的设备名称 [英] Getting friendly device names in python

查看:210
本文介绍了在python中获取友好的设备名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个2端口信号继电器通过USB串行接口连接到我的计算机.使用pyserial模块,我可以轻松控制这些继电器.但是,这是基于这样的假设:我事先知道设备分配给了哪个COM端口(或/dev-node).

I have an 2-port signal relay connected to my computer via a USB serial interface. Using the pyserial module I can control these relays with ease. However, this is based on the assumption that I know beforehand which COM-port (or /dev-node) the device is assigned to.

对于我正在做的项目来说,这还不够,因为我不想假设设备总是被分配给Windows中的COM7.我需要能够使用python在可能的平台(Win,Linux,OSX(我想这与Linux方法类似))上以编程方式识别设备.如标题所示,也许通过枚举系统上的USB设备,并以某种方式获得更友好的名称. Windows和Linux是最重要的支持平台.

For the project I'm doing that's not enough since I don't want to assume that the device always gets assigned to for example COM7 in Windows. I need to be able to identify the device programatically across the possible platforms (Win, Linux, OSX (which I imagine would be similar to the Linux approach)), using python. Perhaps by, as the title suggests, enumerate USB-devices on the system and somehow get more friendly names for them. Windows and Linux being the most important platforms to support.

任何帮助将不胜感激!


似乎pyudev-module非常适合Linux系统.有没有人有任何经验?


Seems like the pyudev-module would be a good fit for Linux-systems. Has anyone had any experience with that?

推荐答案

对于Linux,如果只需要枚举设备,则甚至可以跳过项目的pyudev依赖项,只需解析/sbin/udevadm info --export-db命令的输出(不需要root特权).它将转储有关当前设备和类别的所有信息,包括USB设备的USB产品ID,这些信息应足以标识您的USB到串行适配器.当然,您也可以使用pyudev来做到这一点.

Regarding Linux, if all you need is to enumerate devices, you can even skip pyudev dependency for your project, and simply parse the output of /sbin/udevadm info --export-db command (does not require root privileges). It will dump all information about present devices and classes, including USB product IDs for USB devices, which should be more then enough to identify your USB-to-serial adapters. Of course, you can also do this with pyudev.

这篇关于在python中获取友好的设备名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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