如何收集串口名称和设备名称 [英] how to collect the name of the serial port and device names

查看:106
本文介绍了如何收集串口名称和设备名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好朋友可以解释如何收集串口名称和设备名称。



例如: http://prntscr.com/2upecb [ ^ ]



hello friend can you explain how to collect the serial port name and the name of the device.

for example: http://prntscr.com/2upecb[^]

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ComboBox1.Items.AddRange(IO.Ports.SerialPort.GetPortNames)
    End Sub
End Class





谢谢..



THANKS..

推荐答案

你给出的例子不是串口 - 它是关于调制解调器的。

串口不够聪明,不知道连接到它们的是什么 - 调制解调器知道他们正在使用哪个串口。

您可以用这种方式枚举调制解调器(或其他设备):



添加对system.management.dll到你的应用程序。





The example you give is not about serial ports - it is about modems.
Serial ports are not intelligent enough to know what is connected to them - modems know which serial port they are using.
You can enumerate modems (or other devices) in this way:

Add a reference to system.management.dll to your app.


 Imports System.Management
 Private Sub LoadModemList()
    Try
        Dim mngSearch As New ManagementObjectSearcher("Select * From Win32_POTSModem")
        Dim mngColl As ManagementObjectCollection = mngSearch.Get
        Dim mngObj As ManagementObject

        For Each mngObj In mngColl
            Debug.WriteLine(CType(mngObj.Item("AttachedTo"),
           String) & " - " & CType(mngObj.Item("Name"), String))
        Next

    Catch ex As Exception

    End Try

End Sub


这篇关于如何收集串口名称和设备名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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