0

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

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

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

4

2 回答 2

2

请参阅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%20Ports http://32feet.codeplex.com/wikipage?title=General%20Bluetooth%20Data%20Connections

于 2011-05-13T14:56:01.123 回答
2

您可以查看注册表。

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

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

于 2013-10-11T17:17:01.907 回答