简体   繁体   English

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

[英]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? 如何从C#程序识别哪些COM端口连接到蓝牙?

Here is my requirement. 这是我的要求。 Let us assume the COM ports in my computer are connected to various devices. 让我们假设计算机中的COM端口已连接到各种设备。 Let's say we have COM ports 1 through 9, and 2, 3, 4, 5, and 7 are connected at the moment. 假设我们有COM端口1到9,并且现在连接了2、3、4、5和7。 Now I need to identify, among ports 2, 3, 4, 5 and 7, which ports are connected to BlueTooth devices? 现在,我需要在端口2、3、4、5和7中确定哪些端口连接到了蓝牙设备?

I need to do this using a C# program. 我需要使用C#程序执行此操作。 Any advice? 有什么建议吗?

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. 如果您有多个设备,则也可以有“ \\ Device \\ BthModem1”或“ \\ Device \\ BthModem2”等。

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. 请参阅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
… …

Of course I'm not a fan of virtual COM port and always recommend using a direct sockets/API connection where possible. 当然,我不是虚拟COM端口的拥护者,因此始终建议尽可能使用直接套接字/ API连接。 http://32feet.codeplex.com/wikipage?title=Bluetooth%20Serial%20Ports http://32feet.codeplex.com/wikipage?title=General%20Bluetooth%20Data%20Connections http://32feet.codeplex.com/wikipage?title= 蓝牙%20Serial% 20Ports http://32feet.codeplex.com/wikipage?title=General%20Bluetooth%20Data%20Connections

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM