python : How to detect device name/id on a serial COM(python:如何检测串行 COM 上的设备名称/ID)
问题描述
我想了解如何在 python 中执行此操作:
I would like some indication on how to do this in python:
识别串口中指定名称的端口(DeviceVCP0和DeviceVCP1这些是通过在regedit窗口中浏览获得的)
Identify the port named a specific name in the serial com (DeviceVCP0 and DeviceVCP1 these are get by browsing in regedit window)
并获取插入设备的id
我已经可以使用扫描活动串行端口 COM 的 pySerial 代码识别可用的 COM
I can already identify the avalable COM with this pySerial code that scan up the active serial port COM
import serial
def scan():
"""scan for available ports. return a list of tuples (num, name)"""
available = []
for i in range(256):
try:
s = serial.Serial(i)
available.append( (i, s.portstr))
s.close() # explicit close 'cause of delayed GC in java
except serial.SerialException:
pass
return available
if __name__=='__main__':
print "Found ports:"
for n,s in scan():
print "(%d) %s" % (n,s)
提前致谢
推荐答案
我不确定你使用的是什么操作系统,但这是在 Win7-x64 中的
I am not sure what operating system you are using, but this is in Win7-x64
import win32com.client
wmi = win32com.client.GetObject("winmgmts:")
for serial in wmi.InstancesOf("Win32_SerialPort"):
print (serial.Name, serial.Description)
使用此信息,您可以解析它并获取 COM 编号.您可以在此处获取 Serial 实例的其他属性:http://msdn.microsoft.com/en-us/library/aa394413(v=vs.85).aspx
Using this information, you can parse it and get the COM numbers. You can get other attributes of the Serial instances here: http://msdn.microsoft.com/en-us/library/aa394413(v=vs.85).aspx
这篇关于python:如何检测串行 COM 上的设备名称/ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:python:如何检测串行 COM 上的设备名称/ID
基础教程推荐
- Discord.py 缺少必需的参数 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
