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