python:如何检测串行 COM 上的设备名称/ID

2023-07-23Python开发问题
85

本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

在xarray中按单个维度的多个坐标分组
groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)...
2024-08-22 Python开发问题
15

Pandas中的GROUP BY AND SUM不丢失列
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)...
2024-08-22 Python开发问题
17

pandas 有从特定日期开始的按月分组的方式吗?
Is there a way of group by month in Pandas starting at specific day number?( pandas 有从特定日期开始的按月分组的方式吗?)...
2024-08-22 Python开发问题
10

GROUP BY+新列+基于条件的前一行抓取值
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)...
2024-08-22 Python开发问题
18

PANDA中的Groupby算法和插值算法
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)...
2024-08-22 Python开发问题
11

PANAS-基于列对行进行分组,并将NaN替换为非空值
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)...
2024-08-22 Python开发问题
10