开发者

How to identify which COM ports are connected to BlueTooth from a C# Program?

How to identify which COM ports are connected to BlueTooth from a C# Program?

Here is my requirement. Let us assume the COM ports in my computer are connected to various devices. Let's say we have COM ports 1 through 9, and 2, 3, 4, 5,开发者_如何学JAVA and 7 are connected at the moment. Now I need to identify, among ports 2, 3, 4, 5 and 7, which ports are connected to BlueTooth devices?

I need to do this using a C# program. Any advice?


See http://32feet.codeplex.com/wikipage?title=Getting%20Virtual%20COM%20Port%20Names In brief use WMI to see the BluetoothAddress in the port hardware id.

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

Of course I'm not a fan of virtual COM port and always recommend using a direct sockets/API connection where possible. http://32feet.codeplex.com/wikipage?title=Bluetooth%20Serial%20Ports http://32feet.codeplex.com/wikipage?title=General%20Bluetooth%20Data%20Connections


You can look in the registry.

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

If you have more than one device, there can also be "\Device\BthModem1" or "\Device\BthModem2" ect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜