【问题标题】:How to identify which COM ports are connected to BlueTooth from a C# Program?如何从 C# 程序识别哪些 COM 端口连接到蓝牙?
【发布时间】:2011-05-13 07:09:28
【问题描述】:

如何从 C# 程序中识别连接到蓝牙的 COM 端口?

这是我的要求。让我们假设我电脑中的 COM 端口连接到各种设备。假设我们有 COM 端口 1 到 9,并且此时连接了 2、3、4、5 和 7。现在我需要在端口 2、3、4、5 和 7 中识别出哪些端口连接到蓝牙设备?

我需要使用 C# 程序来执行此操作。有什么建议吗?

【问题讨论】:

    标签: c# bluetooth virtual-serial-port


    【解决方案1】:

    http://32feet.codeplex.com/wikipage?title=Getting%20Virtual%20COM%20Port%20Names 简要使用WMI查看端口硬件id中的BluetoothAddress。

    C:\> Get-WmiObject -query "select DeviceID,PNPDeviceID from Win32_SerialPort"
    DeviceID     : COM66 
    PNPDeviceID  : BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}\7&1D80ECD3&0&00803A686519_C00000003
    … …
    

    当然,我不喜欢虚拟 COM 端口,并且总是建议尽可能使用直接套接字/API 连接。 http://32feet.codeplex.com/wikipage?title=Bluetooth%20Serial%20Portshttp://32feet.codeplex.com/wikipage?title=General%20Bluetooth%20Data%20Connections

    【讨论】:

      【解决方案2】:

      您可以查看注册表。

      string commport =(string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM",     @"\Device\BthModem0", "");
      

      如果您有多个设备,还可以有“\Device\BthModem1”或“\Device\BthModem2”等。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-03-16
        • 2016-02-21
        • 1970-01-01
        • 2012-01-07
        • 2016-05-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多