如何从 C# 程序识别哪些 COM 端口连接到蓝牙?
这是我的要求。让我们假设我电脑中的 COM 端口连接到各种设备。假设我们有 COM 端口 1 到 9,并且此时连接了 2、3、4、5 和 7。现在我需要识别端口 2、3、4、5 和 7 中,哪些端口连接到蓝牙设备?
我需要使用 C# 程序来执行此操作。有什么建议吗?
如何从 C# 程序识别哪些 COM 端口连接到蓝牙?
这是我的要求。让我们假设我电脑中的 COM 端口连接到各种设备。假设我们有 COM 端口 1 到 9,并且此时连接了 2、3、4、5 和 7。现在我需要识别端口 2、3、4、5 和 7 中,哪些端口连接到蓝牙设备?
我需要使用 C# 程序来执行此操作。有什么建议吗?
请参阅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
您可以查看注册表。
string commport =(string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", @"\Device\BthModem0", "");
如果您有多个设备,还可以有“\Device\BthModem1”或“\Device\BthModem2”等。